CSS Reference ยท Typography
The text-decoration property
Reference for the CSS text-decoration shorthand: line, style, color and thickness in one declaration, removing link underlines, and how it propagates.
The text-decoration property is a shorthand that draws lines on text: underline, overline or line-through. In one declaration you can set the line type, its style (solid, wavy and so on), its color and its thickness. The most common use by far is text-decoration: none to remove the underline from links.
a { text-decoration: underline wavy #c0392b 2px; }
Try it
The underline is drawn across the whole parent text, including inline children, in the parent's color. A child cannot switch it off; only an out-of-flow or inline-block child starts its own decoration context.
Syntax
text-decoration: <text-decoration-line> || <text-decoration-style> || <text-decoration-color> || <text-decoration-thickness>;
- Initial value:
none(each longhand at its own initial value:none,solid,currentcolor,auto) - Applies to: all elements; also
::first-letterand::first-line - Inherited: no, but decorations on an element are drawn across its in-flow inline descendants
- Animatable: the color and thickness parts are animatable
- Computed value: as each longhand
Values
| Value | Description |
|---|---|
none |
No decoration. |
underline, overline, line-through |
The line to draw. They can be combined, such as underline overline. |
solid, double, dotted, dashed, wavy |
The line style. |
<color> |
The line color. By default it matches the text (currentcolor). |
<length>, <percentage>, from-font, auto |
The line thickness. |
Usage notes
- Omitted parts reset. Because it is a shorthand,
text-decoration: underlineresets style, color and thickness to their initial values. - No separate decoration for children. A decoration set on a parent cannot be removed by
noneon an inline child. Apply the decoration to the element that should have it instead. - Color of the line. The line uses its own color if set; otherwise it uses the element's
colorat the point where the decoration was declared. - Links. Underlines are an important cue for links. If you remove them, make links distinguishable another way (color contrast of 3:1 against surrounding text, plus a hover or focus indicator).
- Underlines skip descenders. Browsers by default avoid crossing letters like "g" and "y" (
text-decoration-skip-ink). - Fine control. Use
text-underline-offsetto move the underline away from the text. - Not for layout. The decoration does not affect box size.
text-decoration: line-throughis a good way to show removed prices; add visually hidden text for screen reader users if the meaning matters, or use the<del>element.
Browser support
The shorthand with line, style and color works in every modern browser. Support for the thickness part in the shorthand is also widespread, but check a compatibility table for older versions.
Related
text-decoration-line,text-decoration-style,text-decoration-color,text-decoration-thicknessโ the longhandstext-underline-offsetโ moves the underlinetext-shadowโ shadows on text- Lesson: Styling Text