UGURUS offers elite coaching and mentorship for agency owners looking to grow. Start with the free Agency Accelerator today.
The text-decoration-line
property decorates text with an underline, overline, line-through, or a combination of those lines.
p {
text-decoration-line: underline;
}
Values
none
: no line is added, and any existing lines are removed — for examplenone
removes the default underline on links.underline
: adds a 1px underline below the text.overline
: adds a 1px overline above the text.line-through
: adds a 1px line through the text.inherit
: inherits the decoration of the parent.
The value blink
is in the W3C spec, but it is deprecated and will not work in any current browser. When it worked, it made the text appear to “blink” by rapidly toggling it between 0% and 100% opacity.
Combining Values
You can combine the underline
, overline
, or line-through
values in a space-separated list to add multiple decoration lines:
p {
text-decoration-line: overline underline line-through;
}
Usage
The text-decoration-line
property is practically identical to the original text-decoration
property. If all you want to do is add a line or lines to your text, text-decoration
is a better choice because it it supported by every browser, even very old ones. Generally, using a text-decoration-line
declaration only makes sense when you’re writing a longhand style rule that includes text-decoration-style
or a text-decoration-color
declaration. If you want to use all three together, you can use the shorthand text-decoration
property.
Shorthand
text-decoration-line
can be used in combination with text-decoration-style
and text-decoration-color
in the shorthand CSS3 text-decoration
property (currently only Firefox fully supports this):
.underlined {
text-decoration: underline dotted red;
}
Demo
This demo will work in Safari, Firefox, and Chrome with experimental web platform features enabled. The blink
value is not included.
More Information
Browser Support
Chrome | Safari | Firefox | Opera | IE | Android | iOS |
---|---|---|---|---|---|---|
31 * † | 7.1 * | 6 ‡ | None | None | None | 8 * |
* with -webkit
prefix
† with experimental Web Platform features flag enabled
‡ 6 – 35 with -moz
prefix, unprefixed as of 36.
Related
text-decoration-color
.element { text-decoration-color: orange; }
text-decoration-skip
.element { text-decoration-skip: ink; }
text-decoration-skip-ink
.element {text-decoration-skip-ink: none; }
text-decoration-style
.element { text-decoration-style: wavy; }
text-decoration-thickness
.element { text-decoration-thickness: 2px; }
Hey there,
Is there any way to achieve this https://i.imgur.com/8C1nLyc.png ?
user defined width of overline ?
Yeah, I think that would be possible but using a separate div instead of the
text-decoration-line
property and relying on percentages based on the width of the parent container. Here are a couple of options: https://codepen.io/geoffgraham/pen/LgOymmThanks a lot Goeff, It worked :)