CSS text-decoration
The text-decoration property is a shorthand property for setting text-decoration-line, text-decoration-style, and text-decoration-color in one declaration.
When using the text-decoration shorthand property, omitted values are set to their initial values.
Syntax
Possible Values
text-decoration-line- Specifies what line decorations, if any, are added to the element. The following values are valid:
none- Neither produces nor inhibits text decoration.
underline- Each line of text is underlined.
overline- Each line of text has a line over it.
line-through- Each line of text has a line through the middle.
blink- The text blinks (alternates between visible and invisible). Note that this value is deprecated in favor of CSS animations.
text-decoration-style- The style of the text decoration.
solid- A solid line.
wavy- A wavy line.
dotted- A dotted line.
dashed- A line consisting of dashes.
double- A double solid line.
text-decoration-color- The color of the text decoration. Can be any valid color.
In addition, all CSS properties also accept the following CSS-wide keyword values as the sole component of their property value:
initial- Represents the value specified as the property's initial value.
inherit- Represents the computed value of the property on the element's parent.
unset- This value acts as either
inheritorinitial, depending on whether the property is inherited or not. In other words, it sets all properties to their parent value if they are inheritable or to their initial value if not inheritable.
Basic Property Information
- Initial Value
- See individual properties (effectively
nonefor line,solidfor style,currentcolorfor color) - Applies To
- All elements
- Inherited?
- No
- Media
- Visual
- Animatable
- Yes, depending on individual longhands (e.g., color and thickness animate; style does not). (see example)
Example Code
Basic CSS
Here's an example of a basic declaration. A declaration consists of the property and its values for the various longhand properties.
Any omitted values are set to their initial value. So the following is also valid.
In fact, this is the only syntax recognized by CSS1 and CSS2 (as they don't support the longhand properties).
So, you could use the following code to provide CSS3 features, while still providing backwards compatibility for CSS1 and CSS2 browsers:
In CSS1 and CSS2 browsers, both the link text and its underline will be orange. Its underline will be solid (this is the only option prior to CSS3).
In CSS3 browsers, the link text will be orange and its underline will be green. Its underline will also be dotted.
Working Example within an HTML Document
Official Specifications
- CSS Text Decoration Module Level 3 (W3C Editor's Draft)
- CSS Text Decoration Module Level 3 (W3C Candidate Recommendation)
- CSS Level 2.1 (W3C Recommendation 07 June 2011)
- CSS Level 1 (W3C Recommendation 17 Dec 1996)
Browser Support
Browser support for CSS properties can vary, particularly for newer or experimental features. Check current browser compatibility before using a property in production, especially when supporting older browsers.
The following table provided by Caniuse.com shows the level of browser support for this feature.
Initial Value
CSS properties have an initial value that applies when the property has not been explicitly set. The initial value is different from the value inherited from a parent element and may vary between properties.
Inheritance
Some CSS properties inherit their computed value from their parent element by default, while others do not. The inherit, initial, unset, and revert keywords can also be used to control how a property gets its value.
Vendor Prefixes
Most modern CSS properties use the standard, unprefixed syntax. Vendor-prefixed properties such as -webkit- are mainly relevant to older browser versions or specific features and should only be used when required by your browser support targets.