Home > Web Front-end > CSS Tutorial > How to Create a Colored Underline for Text in HTML?

How to Create a Colored Underline for Text in HTML?

Barbara Streisand
Release: 2024-11-14 09:54:01
Original
698 people have browsed it

How to Create a Colored Underline for Text in HTML?

Customizing Underline Color

In HTML coding, you may encounter a situation where you want to underline text in a specific color, but leave the text itself a different color. The problem arises when you use a single element to style both the text and the underline, leading to uniform coloring.

To address this issue, you can utilize the latest CSS3 property: text-decoration-color. This property allows you to independently control the color of the underline, enabling you to create text in one color and an underline in a different color within the same element.

Here's a CSS code example:

p {
  text-decoration: underline;
  -webkit-text-decoration-color: red; /* for Safari browsers */
  text-decoration-color: red;
}
Copy after login

And an HTML example to display the result:

<p>Black text with red underline in one element - no wrapper elements here!</p>
Copy after login

By implementing this CSS property, you can split the styling of the text and underline, achieving your desired color customization without the need for additional wrapper elements.

The above is the detailed content of How to Create a Colored Underline for Text in HTML?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template