CSS text-decoration Property

The CSS text-decoration property is a shorthand that adds and styles decorative lines on text, including underlines, overlines, and strikethroughs.

It combines the text-decoration-line, text-decoration-style, text-decoration-color, and text-decoration-thickness properties into a single declaration.

Text decorations are commonly used to identify links, indicate deleted content, emphasize headings, and create visual effects. The shorthand allows the line type, appearance, color, and thickness to be customized independently of the text color.

text-decoration Syntax

The text-decoration shorthand accepts a decoration line, style, color, and thickness. These components can be combined in one declaration, and their order is generally flexible.

Basic Syntax

p {
  text-decoration: underline;
}

This adds a solid underline using the current text color and the browser's automatic decoration thickness.

Common Values

.example {
  text-decoration: none;
}
.example {
  text-decoration: underline;
}
.example {
  text-decoration: overline;
}
.example {
  text-decoration: line-through;
}
.example {
  text-decoration: underline dotted;
}
.example {
  text-decoration: underline red;
}
.example {
  text-decoration: underline wavy blue;
}
.example {
  text-decoration: underline solid #2563eb 2px;
}

Combining Components

.example {
  text-decoration: underline dashed green 3px;
}

This declaration creates a green dashed underline with a thickness of 3px.

Multiple Decoration Lines

.example {
  text-decoration: underline overline solid blue;
}

Both an underline and an overline are applied using the same style and color.

CSS-Wide Keywords

.example {
  text-decoration: initial;
}
.example {
  text-decoration: inherit;
}
.example {
  text-decoration: unset;
}
.example {
  text-decoration: revert;
}
.example {
  text-decoration: revert-layer;
}

The shorthand's initial behavior is equivalent to text-decoration: none solid currentColor auto.

Property Values

The shorthand combines four groups of values, each corresponding to a text-decoration longhand property.

Component Values Description
text-decoration-line none, underline, overline, line-through, blink Specifies which decorative lines are applied. The legacy blink keyword does not produce blinking text in modern browsers.
text-decoration-style solid, double, dotted, dashed, wavy Controls the appearance of the decoration lines.
text-decoration-color Any valid CSS color Sets the color of the decoration independently of the text color.
text-decoration-thickness auto, from-font, lengths, percentages Controls the thickness of the decoration lines.

Property Characteristics

Characteristic Value
Initial value none solid currentColor auto
Inherited No, although decorations can propagate visually to descendant text
Applies to All elements
Computed value Determined separately for each longhand component
Animation type Determined by the individual longhand properties
Percentages Accepted for decoration thickness
Related properties text-decoration-line, text-decoration-style, text-decoration-color, text-decoration-thickness
Specification CSS Text Decoration Module Level 3 and Level 4

Valid Examples

.example {
  text-decoration: underline;
}
.example {
  text-decoration: underline dotted;
}
.example {
  text-decoration: line-through red;
}
.example {
  text-decoration: overline double blue;
}
.example {
  text-decoration: underline wavy #dc2626 2px;
}
.example {
  text-decoration: underline solid currentColor from-font;
}
.example {
  text-decoration: underline 10%;
}

Invalid Examples

.example {
  text-decoration: bold;
}
.example {
  text-decoration: underline center;
}
.example {
  text-decoration: underline 5;
}
.example {
  text-decoration: underline dotted dashed;
}
.example {
  text-decoration: underline underline;
}

The shorthand does not accept font-weight values, alignment keywords, unitless numeric thicknesses, or multiple competing values for the same component.

How It Works

Text decorations are drawn in relation to the text being rendered. The browser determines their position using font metrics, writing direction, and other applicable text-decoration properties.

Step 1: Create the Text

<p class="decorated-text">Learn CSS Typography</p>

Step 2: Add a Decoration

.decorated-text {
  text-decoration: underline;
}

The browser draws an underline beneath the text.

Step 3: Change the Style

.decorated-text {
  text-decoration: underline wavy;
}

The underline now uses a wavy appearance.

Step 4: Set the Color

.decorated-text {
  text-decoration: underline wavy #2563eb;
}

The decoration becomes blue, regardless of the text's own color.

Step 5: Adjust the Thickness

.decorated-text {
  text-decoration: underline wavy #2563eb 2px;
}

The browser uses a specified decoration thickness of 2px.

Important Consideration

Decorations are painted as part of text rendering. They do not normally change the dimensions of the element's layout box or add extra spacing between elements.

Decoration Lines

The line component determines which type of decoration is drawn.

The none Value

.example {
  text-decoration: none;
}

Specifies that the element does not introduce a text decoration.

The underline Value

.example {
  text-decoration: underline;
}

Draws a line beneath the text, according to its writing mode and underline positioning rules.

The overline Value

.example {
  text-decoration: overline;
}

Draws a line over the text.

The line-through Value

.example {
  text-decoration: line-through;
}

Draws a line through the text, commonly used to indicate removed or outdated content.

The blink Value

.example {
  text-decoration: blink;
}

The legacy blink keyword is retained for compatibility but does not cause text to blink in modern browsers. Avoid using it for visual effects.

Combining Line Types

.example {
  text-decoration: underline overline;
}

Applies both an underline and an overline.

Important Consideration

The none keyword cannot be combined with another decoration-line keyword in the same declaration.

Decoration Styles

The style component determines the visual appearance of the decoration line.

Solid

.example {
  text-decoration: underline solid;
}

Creates a continuous line. This is the initial decoration style.

Double

.example {
  text-decoration: underline double;
}

Creates two parallel decoration lines.

Dotted

.example {
  text-decoration: underline dotted;
}

Creates a decoration made of dots.

Dashed

.example {
  text-decoration: underline dashed;
}

Creates a decoration made of short line segments.

Wavy

.example {
  text-decoration: underline wavy;
}

Creates a wave-shaped decoration, commonly used for spelling or annotation indicators.

Style Comparison

Style Appearance
solid One continuous line
double Two parallel lines
dotted Series of dots
dashed Series of short segments
wavy Wave-shaped line

The precise rendering of each style may vary slightly between browsers and fonts.

Decoration Colors

The color component controls the color of the decoration line independently of the text color.

Named Color

.example {
  text-decoration: underline red;
}

Hexadecimal Color

.example {
  text-decoration: underline #2563eb;
}

RGB Color

.example {
  text-decoration: underline rgb(37, 99, 235);
}

Current Text Color

.example {
  color: #166534;
  text-decoration: underline currentColor;
}

The currentColor keyword makes the decoration use the element's current text color.

Different Text and Decoration Colors

.example {
  color: #1f2937;
  text-decoration: underline wavy #dc2626;
}

The text remains dark gray while the underline is red.

Transparent Decorations

.example {
  text-decoration: underline transparent;
}

The underline remains specified but is painted transparently. This can be useful when preparing a color transition for a hover effect.

Decoration Thickness

The thickness component controls how thick the decoration line appears.

Automatic Thickness

.example {
  text-decoration: underline auto;
}

The browser selects an appropriate thickness.

Font-Based Thickness

.example {
  text-decoration: underline from-font;
}

Uses the font's preferred decoration thickness when available, with automatic behavior as a fallback.

Fixed Thickness

.example {
  text-decoration: underline 3px;
}

Specifies a thickness of 3px.

Relative Thickness

.example {
  text-decoration: underline 0.12em;
}

Uses a thickness relative to the element's font size.

Percentage Thickness

.example {
  text-decoration: underline 10%;
}

The percentage is calculated relative to the element's font size.

Combining Thickness With Other Components

.example {
  text-decoration: underline dashed #2563eb 2px;
}

This creates a blue dashed underline with a thickness of 2px.

Important Consideration

Very thick decorations can overlap glyphs or become visually distracting. Choose a thickness appropriate for the font size and intended emphasis.

Multiple Decorations

Multiple decoration-line keywords can be specified in a single declaration.

Underline and Overline

.example {
  text-decoration: underline overline;
}

Underline and Strikethrough

.example {
  text-decoration: underline line-through;
}

Three Decoration Lines

.example {
  text-decoration: underline overline line-through;
}

Multiple Lines With a Shared Style

.example {
  text-decoration: underline overline double #2563eb 2px;
}

Both decorations use the specified double style, blue color, and thickness.

Different Styles for Different Lines

The shorthand applies one shared style, color, and thickness to its selected decoration lines. To create different decoration appearances on separate text fragments, use separate elements or other appropriate styling techniques.

Important Consideration

Decoration lines can visually overlap when multiple types are applied. Use combinations selectively to maintain readability.

Shorthand Behavior

The text-decoration shorthand sets four longhand properties simultaneously. Any omitted component is reset to its initial value.

Longhand Version

.example {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: #2563eb;
  text-decoration-thickness: 2px;
}

Equivalent Shorthand

.example {
  text-decoration: underline wavy #2563eb 2px;
}

Omitted Components

.example {
  text-decoration: underline;
}

This sets the line to underline and resets the style to solid, color to currentColor, and thickness to auto.

Shorthand Reset Example

.example {
  text-decoration-color: red;
  text-decoration-thickness: 3px;
  text-decoration: underline;
}

The final shorthand resets the earlier color and thickness values.

Preserving Custom Values

.example {
  text-decoration: underline;
  text-decoration-color: red;
  text-decoration-thickness: 3px;
}

Declaring the longhand properties after the shorthand preserves the desired customization.

Declaration Order

When declarations have the same cascade priority, later declarations override earlier ones for the components they set.

Several related properties provide additional control over the appearance and positioning of text decorations.

Property Purpose
text-decoration-line Specifies underline, overline, line-through, or no decoration.
text-decoration-style Controls whether the line is solid, double, dotted, dashed, or wavy.
text-decoration-color Sets the decoration color.
text-decoration-thickness Controls the line thickness.
text-decoration-skip-ink Controls whether underlines skip portions of glyphs where the line would cross their ink.
text-underline-offset Adjusts the distance between an underline and its normal position.
text-underline-position Controls the positioning of underlines.

Adjusting Underline Offset

.example {
  text-decoration: underline solid #2563eb 2px;
  text-underline-offset: 4px;
}

The underline is offset from its normal position without changing the text's layout dimensions.

Controlling Ink Skipping

.example {
  text-decoration: underline;
  text-decoration-skip-ink: auto;
}

The browser can interrupt an underline where it would cross glyph ink, improving readability.

Positioning Underlines

.example {
  text-decoration: underline;
  text-underline-position: under;
}

The under value positions the underline beneath the text rather than using its usual font-based position.

Important Consideration

The text-decoration shorthand does not include text-decoration-skip-ink, text-underline-offset, or text-underline-position. Set these properties separately.

Practical Examples

Basic Underline

.underlined-text {
  text-decoration: underline;
}

Adds a standard underline.

Colored Underline

.colored-underline {
  color: #1f2937;
  text-decoration: underline #2563eb;
}

Uses a blue underline with dark gray text.

Thick Underline

.thick-underline {
  text-decoration: underline solid #2563eb 3px;
}

Creates a prominent underline.

Wavy Underline

.wavy-underline {
  text-decoration: underline wavy #dc2626 2px;
}

Creates a red wavy underline.

Dashed Underline

.dashed-underline {
  text-decoration: underline dashed #059669 2px;
}

Creates a green dashed underline.

Double Overline

.double-overline {
  text-decoration: overline double #7c3aed;
}

Draws two parallel lines above the text.

Strikethrough

.old-price {
  text-decoration: line-through;
}

Visually marks a previous price. Use appropriate semantic HTML when the text represents deleted or no-longer-accurate information.

Custom Link Underline

.custom-link {
  color: #1d4ed8;
  text-decoration: underline solid currentColor 2px;
  text-underline-offset: 3px;
}

Creates a clearly visible underline that follows the link's text color.

Hover Decoration

.hover-link {
  color: #1d4ed8;
  text-decoration: underline transparent;
  text-underline-offset: 3px;
}
.hover-link:hover,
.hover-link:focus-visible {
  text-decoration-color: currentColor;
}

The underline becomes visible on hover or keyboard focus.

Underline and Overline

.decorated-heading {
  text-decoration: underline overline solid #2563eb 2px;
}

Adds matching decorative lines above and below a heading.

Responsive Decoration Thickness

.responsive-heading {
  font-size: 24px;
  text-decoration: underline solid #2563eb 0.1em;
}
@media (min-width: 768px) {
  .responsive-heading {
    font-size: 36px;
  }
}

The relative thickness scales with the font size.

text-decoration Example

This example demonstrates several decoration types, styles, colors, and thicknesses using the text-decoration shorthand.

HTML Example

<div class="decoration-demo">
  <p class="decoration-underline">Solid Underline</p>
  <p class="decoration-dotted">Dotted Underline</p>
  <p class="decoration-dashed">Dashed Underline</p>
  <p class="decoration-wavy">Wavy Underline</p>
  <p class="decoration-double">Double Overline</p>
  <p class="decoration-strike">Line Through</p>
  <p class="decoration-multiple">Underline and Overline</p>
</div>

CSS Example

.decoration-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.decoration-demo p {
  margin: 0;
  padding: 16px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #1f2937;
  font-size: 18px;
  line-height: 1.6;
  text-align: center;
}
.decoration-demo .decoration-underline {
  text-decoration: underline solid #2563eb 2px;
}
.decoration-demo .decoration-dotted {
  text-decoration: underline dotted #059669 2px;
}
.decoration-demo .decoration-dashed {
  text-decoration: underline dashed #7c3aed 2px;
}
.decoration-demo .decoration-wavy {
  text-decoration: underline wavy #dc2626 2px;
}
.decoration-demo .decoration-double {
  text-decoration: overline double #2563eb 2px;
}
.decoration-demo .decoration-strike {
  text-decoration: line-through solid #dc2626 2px;
}
.decoration-demo .decoration-multiple {
  text-decoration: underline overline solid #059669 2px;
}
Browser Result

Solid Underline

Dotted Underline

Dashed Underline

Wavy Underline

Double Overline

Line Through

Underline and Overline

Each sample uses the same text color and font size, while the decoration line, style, color, and thickness vary.

Comparing the Results

Sample Decoration
Solid Underline Blue continuous underline
Dotted Underline Green dotted underline
Dashed Underline Purple dashed underline
Wavy Underline Red wavy underline
Double Overline Blue double line above the text
Line Through Red line through the text
Underline and Overline Green lines above and below the text

Changing the Decoration Color

.decoration-demo .decoration-underline {
  text-decoration: underline solid #dc2626 2px;
}

The first sample now uses a red underline.

Changing the Thickness

.decoration-demo .decoration-underline {
  text-decoration: underline solid #2563eb 4px;
}

The underline becomes thicker without changing the font size.

Removing a Decoration

.decoration-demo .decoration-underline {
  text-decoration: none;
}

The first sample no longer introduces an underline.

Accessibility Considerations

Text decorations can help communicate meaning, but their use should support readability and recognizable interactive elements.

Keep Links Recognizable

Underlines are a familiar visual indicator for links. Removing them can make links harder to identify, especially when they appear within paragraphs.

Do Not Rely on Color Alone

When links are distinguished from surrounding text, use a persistent non-color indicator such as an underline, or ensure an accessible alternative is available.

Maintain Sufficient Contrast

Choose decoration colors that remain visible against the background. Avoid extremely pale or thin underlines that are difficult to distinguish.

Preserve Keyboard Focus Indicators

Hover effects should have corresponding keyboard-accessible behavior. Use :focus-visible when appropriate.

Use Semantic HTML for Deleted Content

<p>Price: <del>$49</del> $39</p>

The <del> element communicates deleted content semantically. A CSS strikethrough alone does not convey that meaning.

Avoid Excessive Decorations

Combining several line types or using heavy wavy decorations can reduce readability, particularly for smaller text.

Support Text Resizing

Test decorations at increased browser zoom and larger font sizes. Ensure lines do not obscure the characters.

Respect User Preferences

Decorations should remain understandable in high-contrast and forced-colors environments. Test interactive text in these modes.

Common Mistakes

Using an Invalid Line Keyword

.example {
  text-decoration: strike;
}

Use line-through instead of strike.

Using Multiple Conflicting Styles

.example {
  text-decoration: underline dotted dashed;
}

Only one decoration style can be specified in a single shorthand declaration.

Using a Unitless Thickness

.example {
  text-decoration: underline 3;
}

Use a valid length such as 3px, a percentage, auto, or from-font.

Assuming text-decoration Is Inherited

The shorthand is not inherited. However, decorations introduced by an ancestor can continue to be painted across descendant text.

Trying to Remove an Ancestor's Decoration

.parent {
  text-decoration: underline;
}
.parent span {
  text-decoration: none;
}

The descendant's none value does not necessarily remove an underline propagated from its ancestor.

Overwriting Longhand Values

.example {
  text-decoration-color: red;
  text-decoration: underline;
}

The shorthand resets the color to currentColor. Place the longhand declaration afterward or include the color in the shorthand.

Confusing Decoration Color With Text Color

The decoration color and text color are separate. Use color to change the characters and text-decoration-color to change the decoration.

Expecting Decorations to Change Layout Height

Decorations are painted around text and do not normally increase line-box height.

Using CSS Alone to Indicate Deleted Content

Use semantic HTML such as <del> when content has been deleted or changed.

Removing Link Underlines Without an Alternative

Links can become difficult to recognize when their underlines are removed, especially in paragraphs.

Using Overly Thick Decorations

Excessive line thickness can obscure characters or create visual clutter.

Ignoring Browser Rendering Differences

Decoration positions and styles may vary slightly across browsers, operating systems, and fonts.

Important Considerations

Keep the following points in mind when using text-decoration:

  • It is a shorthand for four text-decoration longhand properties.
  • It controls decoration lines, styles, colors, and thicknesses.
  • The initial decoration-line value is none.
  • The initial decoration style is solid.
  • The initial decoration color is currentColor.
  • The initial decoration thickness is auto.
  • The shorthand is not inherited.
  • Decorations can propagate visually to descendant text.
  • A descendant's text-decoration: none does not necessarily remove an ancestor's decoration.
  • The underline keyword draws a line beneath text.
  • The overline keyword draws a line above text.
  • The line-through keyword draws a line through text.
  • Multiple decoration-line keywords can be combined.
  • The none keyword cannot be combined with other line keywords.
  • Supported styles include solid, double, dotted, dashed, and wavy.
  • The decoration color can differ from the text color.
  • Thickness accepts auto, from-font, lengths, and percentages.
  • Percentage thickness is relative to font size.
  • Omitted shorthand components reset to their initial values.
  • Declaration order matters when combining shorthand and longhand properties.
  • Decorations do not normally change the element's layout dimensions.
  • The appearance of decorations can vary by font and browser.
  • The text-underline-offset property controls underline offset separately.
  • The text-underline-position property controls underline positioning separately.
  • The text-decoration-skip-ink property controls ink skipping separately.
  • These three related properties are not included in the shorthand.
  • Underlines help users identify links.
  • Color alone should not be the only indicator of interactive text.
  • Semantic HTML should communicate deleted content.
  • Test decorations with different fonts, zoom levels, and writing modes.

Browser Support

The CSS text-decoration property is widely available across modern browsers. Basic underlines, overlines, and strikethroughs have long-standing support.

More advanced shorthand components, including decoration thickness and certain style combinations, may have different compatibility histories. Check individual longhand properties when supporting older browsers.

For current compatibility information, visit Can I Use? and search for text-decoration.

Basic Compatibility

a {
  text-decoration: underline;
}

Basic underlines are supported across modern browsers.

Advanced Decoration Example

a {
  text-decoration: underline;
}
@supports (text-decoration: underline wavy blue 2px) {
  a {
    text-decoration: underline wavy blue 2px;
  }
}

The feature query checks whether the browser recognizes the complete shorthand declaration.

Fallback Behavior

When an advanced shorthand declaration is unsupported, the browser ignores that declaration. Provide a simpler decoration first when compatibility is important.

Testing Recommendations

Test decoration colors, styles, thicknesses, link states, and underline positioning across target browsers. Verify that decorations remain visible at different font sizes and zoom levels.

Specifications

The text-decoration property is defined in the CSS Text Decoration specifications.

CSS Text Decoration Module Level 3 - text-decoration Property

CSS Text Decoration Module Level 4

The specifications define decoration lines, styles, colors, thickness, painting behavior, and related text-decoration controls.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: text-decoration