CSS text-decoration-color Property
The CSS text-decoration-color property specifies the color of decorative lines applied to text, including underlines, overlines, and strikethroughs.
It allows decoration lines to use a different color from the text itself. The property accepts CSS color values, including named colors, hexadecimal values, RGB, HSL, and currentColor.
The property is one component of the text-decoration shorthand. It changes the decoration color but does not create a decoration line by itself.
text-decoration-color Syntax
The text-decoration-color property accepts any valid CSS color value.
Basic Syntax
p {
text-decoration-line: underline;
text-decoration-color: blue;
}
This creates a blue underline beneath the paragraph text.
Common Color Values
.example {
text-decoration-color: red;
}
.example {
text-decoration-color: #2563eb;
}
.example {
text-decoration-color: rgb(37, 99, 235);
}
.example {
text-decoration-color: hsl(221 83% 53%);
}
.example {
text-decoration-color: currentColor;
}
.example {
text-decoration-color: transparent;
}
Using the text-decoration Shorthand
.example {
text-decoration: underline solid #2563eb 2px;
}
The shorthand sets the decoration line, style, color, and thickness in one declaration.
CSS-Wide Keywords
.example {
text-decoration-color: initial;
}
.example {
text-decoration-color: inherit;
}
.example {
text-decoration-color: unset;
}
.example {
text-decoration-color: revert;
}
.example {
text-decoration-color: revert-layer;
}
The initial value is currentColor, which uses the element's current text color.
Property Values
All valid CSS color values can be used to specify a text decoration color.
| Value | Description |
|---|---|
| Named color | Uses a predefined color keyword such as red, blue, or green. |
| Hexadecimal | Uses a hexadecimal color such as #2563eb. |
rgb() |
Defines the color using red, green, and blue components. |
hsl() |
Defines the color using hue, saturation, and lightness. |
hwb() |
Defines the color using hue, whiteness, and blackness. |
currentColor |
Uses the element's current text color. This is the initial value. |
transparent |
Makes the decoration fully transparent. |
| Other CSS color functions | Accepts valid color values such as lab(), oklch(), and color(), subject to browser support. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | currentColor |
| Inherited | No |
| Applies to | All elements |
| Computed value | Computed CSS color |
| Animation type | By computed color |
| Percentages | Accepted within color functions where permitted |
| Related properties | text-decoration, text-decoration-line, text-decoration-style, text-decoration-thickness |
| Specification | CSS Text Decoration Module Level 3 |
Valid Examples
.example {
text-decoration-color: blue;
}
.example {
text-decoration-color: #dc2626;
}
.example {
text-decoration-color: rgb(220 38 38);
}
.example {
text-decoration-color: hsl(0 72% 51%);
}
.example {
text-decoration-color: rgb(37 99 235 / 50%);
}
.example {
text-decoration-color: currentColor;
}
.example {
text-decoration-color: transparent;
}
Invalid Examples
.example {
text-decoration-color: underline;
}
.example {
text-decoration-color: dotted;
}
.example {
text-decoration-color: 10px;
}
.example {
text-decoration-color: 50%;
}
.example {
text-decoration-color: red blue;
}
The property accepts one CSS color value, not decoration-line keywords, styles, lengths, or multiple separate colors.
How It Works
The text-decoration-color property changes the color used to paint decoration lines introduced by the element.
It does not change the text color or determine which decoration line is drawn.
Step 1: Create the Text
<p class="decorated-text">Learn CSS Typography</p>
Step 2: Add an Underline
.decorated-text {
text-decoration-line: underline;
}
The browser draws an underline using the default decoration color.
Step 3: Change the Decoration Color
.decorated-text {
text-decoration-line: underline;
text-decoration-color: #2563eb;
}
The underline becomes blue.
Step 4: Use a Different Text Color
.decorated-text {
color: #1f2937;
text-decoration-line: underline;
text-decoration-color: #2563eb;
}
The text remains dark gray while the underline is blue.
Step 5: Customize the Line
.decorated-text {
color: #1f2937;
text-decoration-line: underline;
text-decoration-style: wavy;
text-decoration-color: #2563eb;
text-decoration-thickness: 2px;
}
The result is a blue wavy underline with a thickness of 2px.
Important Consideration
A decoration line must exist for the color to be visible. Setting text-decoration-color alone does not create an underline, overline, or strikethrough.
Named Colors
Named colors provide a simple way to specify decoration colors without numeric values.
Red Underline
.example {
text-decoration-line: underline;
text-decoration-color: red;
}
Blue Overline
.example {
text-decoration-line: overline;
text-decoration-color: blue;
}
Green Strikethrough
.example {
text-decoration-line: line-through;
text-decoration-color: green;
}
Using the Shorthand
.example {
text-decoration: underline dotted purple;
}
This creates a purple dotted underline.
When to Use Named Colors
Named colors are convenient for simple examples and standard colors. Hexadecimal values or color functions provide more precise control over custom color palettes.
Hexadecimal Colors
Hexadecimal colors define red, green, and blue components using hexadecimal notation.
Six-Digit Hexadecimal
.example {
text-decoration-line: underline;
text-decoration-color: #2563eb;
}
Three-Digit Hexadecimal
.example {
text-decoration-line: underline;
text-decoration-color: #f00;
}
The value #f00 is equivalent to #ff0000.
Eight-Digit Hexadecimal
.example {
text-decoration-line: underline;
text-decoration-color: #2563eb80;
}
The final two digits specify alpha transparency.
Using the Shorthand
.example {
text-decoration: underline solid #059669 3px;
}
This creates a green underline with a thickness of 3px.
When to Use Hexadecimal Colors
Hexadecimal values are useful when matching a defined website color palette or design system.
RGB and HSL Colors
CSS color functions provide additional control over decoration colors and transparency.
RGB Color
.example {
text-decoration-line: underline;
text-decoration-color: rgb(37, 99, 235);
}
Modern RGB Syntax
.example {
text-decoration-line: underline;
text-decoration-color: rgb(37 99 235);
}
RGB With Transparency
.example {
text-decoration-line: underline;
text-decoration-color: rgb(37 99 235 / 60%);
}
The decoration uses a partially transparent blue.
HSL Color
.example {
text-decoration-line: underline;
text-decoration-color: hsl(221 83% 53%);
}
HSL With Transparency
.example {
text-decoration-line: underline;
text-decoration-color: hsl(221 83% 53% / 50%);
}
Using CSS Variables
:root {
--decoration-color: #2563eb;
}
.example {
text-decoration-line: underline;
text-decoration-color: var(--decoration-color);
}
Custom properties make it easier to reuse and update decoration colors throughout a website.
The currentColor Value
The currentColor keyword uses the element's current text color as the decoration color.
It is the initial value of text-decoration-color.
Basic Example
.example {
color: #2563eb;
text-decoration-line: underline;
text-decoration-color: currentColor;
}
Both the text and underline are blue.
Changing the Text Color
.example {
color: #059669;
text-decoration-line: underline;
text-decoration-color: currentColor;
}
The underline follows the updated green text color.
Hover Example
.example {
color: #2563eb;
text-decoration: underline solid currentColor 2px;
}
.example:hover {
color: #dc2626;
}
When the text color changes on hover, the decoration color changes with it.
When to Use currentColor
Use currentColor when the decoration should remain synchronized with the text color, including interactive states and theme changes.
Transparent Colors
The transparent keyword makes a decoration invisible without removing the decoration-line setting.
Transparent Underline
.example {
text-decoration-line: underline;
text-decoration-color: transparent;
}
The underline remains defined but is not visibly painted.
Partially Transparent Underline
.example {
text-decoration-line: underline;
text-decoration-color: rgb(37 99 235 / 50%);
}
The underline is painted with 50% opacity.
Hover Reveal
.hover-link {
text-decoration-line: underline;
text-decoration-color: transparent;
}
.hover-link:hover,
.hover-link:focus-visible {
text-decoration-color: currentColor;
}
The underline becomes visible when the link is hovered or receives keyboard focus.
Smooth Color Transition
.hover-link {
text-decoration-line: underline;
text-decoration-color: transparent;
transition: text-decoration-color 200ms ease;
}
.hover-link:hover,
.hover-link:focus-visible {
text-decoration-color: currentColor;
}
The decoration color transitions from transparent to the current text color.
Important Consideration
Do not hide link underlines unless the link remains clearly identifiable through another accessible visual indicator.
Decoration Types
The text-decoration-color property works with the decoration lines specified by text-decoration-line.
Underline
.example {
text-decoration-line: underline;
text-decoration-color: #2563eb;
}
Creates a blue underline.
Overline
.example {
text-decoration-line: overline;
text-decoration-color: #059669;
}
Creates a green overline.
Line Through
.example {
text-decoration-line: line-through;
text-decoration-color: #dc2626;
}
Creates a red strikethrough.
Multiple Decoration Lines
.example {
text-decoration-line: underline overline;
text-decoration-color: #7c3aed;
}
Both lines use the same purple color.
Different Colors for Different Lines
A single element's text-decoration-color value applies to the decoration lines introduced by that element. It does not assign separate colors to individual line types.
To create independently colored decorations, use separate elements or another appropriate styling technique.
Important Consideration
The decoration color does not determine the line style or thickness. Use text-decoration-style and text-decoration-thickness for those adjustments.
Relationship With text-decoration
The text-decoration-color property is one of four longhand properties included in the text-decoration shorthand.
| Property | Purpose |
|---|---|
text-decoration-line |
Specifies the decoration line type. |
text-decoration-style |
Specifies the decoration line style. |
text-decoration-color |
Specifies the decoration line color. |
text-decoration-thickness |
Specifies the decoration line thickness. |
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;
}
Shorthand Reset Behavior
.example {
text-decoration-color: red;
text-decoration: underline;
}
The final shorthand resets the decoration color to currentColor.
Preserving the Custom Color
.example {
text-decoration: underline;
text-decoration-color: red;
}
Declaring the color after the shorthand preserves the red underline.
Important Consideration
When declarations have the same cascade priority, their order matters. A later shorthand can reset previously specified longhand values.
Color Transitions
The text-decoration-color property supports color interpolation, allowing decoration colors to change smoothly with CSS transitions and animations.
Basic Transition
.transition-link {
text-decoration: underline solid #2563eb 2px;
transition: text-decoration-color 200ms ease;
}
.transition-link:hover {
text-decoration-color: #dc2626;
}
The underline changes smoothly from blue to red on hover.
Hover and Keyboard Focus
.transition-link {
text-decoration: underline solid #2563eb 2px;
transition: text-decoration-color 200ms ease;
}
.transition-link:hover,
.transition-link:focus-visible {
text-decoration-color: #dc2626;
}
The same color transition applies to pointer hover and keyboard focus.
Transition From Transparent
.transition-link {
text-decoration: underline solid transparent 2px;
transition: text-decoration-color 200ms ease;
}
.transition-link:hover,
.transition-link:focus-visible {
text-decoration-color: currentColor;
}
The underline fades into view without changing the decoration-line type.
Respect Reduced Motion Preferences
.transition-link {
transition: text-decoration-color 200ms ease;
}
@media (prefers-reduced-motion: reduce) {
.transition-link {
transition: none;
}
}
This removes the transition for users who request reduced motion.
Important Consideration
Animating text-decoration-color changes the painted decoration color without normally changing the element's layout dimensions.
Practical Examples
Blue Underline
.blue-underline {
text-decoration-line: underline;
text-decoration-color: #2563eb;
}
Creates a blue underline beneath the text.
Red Wavy Underline
.wavy-underline {
text-decoration-line: underline;
text-decoration-style: wavy;
text-decoration-color: #dc2626;
}
Creates a red wavy underline.
Green Dashed Underline
.dashed-underline {
text-decoration: underline dashed #059669 2px;
}
Creates a green dashed underline.
Purple Overline
.purple-overline {
text-decoration-line: overline;
text-decoration-color: #7c3aed;
}
Creates a purple line above the text.
Red Strikethrough
.old-price {
text-decoration-line: line-through;
text-decoration-color: #dc2626;
}
Displays a red strikethrough. Use semantic HTML when the text represents deleted information.
Different Text and Underline Colors
.custom-link {
color: #1f2937;
text-decoration-line: underline;
text-decoration-color: #2563eb;
}
The text is dark gray while the underline is blue.
Custom Link Decoration
.custom-link {
color: #1d4ed8;
text-decoration: underline solid #2563eb 2px;
text-underline-offset: 3px;
}
Creates a blue underline with a custom thickness and offset.
Hover Color Change
.hover-link {
text-decoration: underline solid #2563eb 2px;
}
.hover-link:hover,
.hover-link:focus-visible {
text-decoration-color: #dc2626;
}
The underline becomes red on hover or keyboard focus.
Using a Custom Property
:root {
--link-decoration: #2563eb;
}
.custom-link {
text-decoration-line: underline;
text-decoration-color: var(--link-decoration);
}
Allows the underline color to be managed through a reusable custom property.
Responsive Typography
.responsive-heading {
font-size: 24px;
text-decoration: underline solid #2563eb 0.1em;
}
@media (min-width: 768px) {
.responsive-heading {
font-size: 36px;
}
}
The underline retains its color while the relative thickness scales with the font size.
text-decoration-color Example
This example compares several decoration colors using the same text color, font size, decoration line, and thickness.
HTML Example
<div class="decoration-color-demo">
<p class="color-blue">Blue Underline</p>
<p class="color-red">Red Underline</p>
<p class="color-green">Green Underline</p>
<p class="color-purple">Purple Underline</p>
<p class="color-current">Current Text Color</p>
<p class="color-transparent">Transparent Underline</p>
</div>
CSS Example
.decoration-color-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 12px;
}
.decoration-color-demo p {
margin: 0;
padding: 16px;
border: 1px solid #cbd5e1;
background: #f8fafc;
color: #1f2937;
font-size: 18px;
line-height: 1.6;
text-align: center;
text-decoration-line: underline;
text-decoration-style: solid;
text-decoration-thickness: 3px;
text-underline-offset: 4px;
}
.decoration-color-demo .color-blue {
text-decoration-color: #2563eb;
}
.decoration-color-demo .color-red {
text-decoration-color: #dc2626;
}
.decoration-color-demo .color-green {
text-decoration-color: #059669;
}
.decoration-color-demo .color-purple {
text-decoration-color: #7c3aed;
}
.decoration-color-demo .color-current {
text-decoration-color: currentColor;
}
.decoration-color-demo .color-transparent {
text-decoration-color: transparent;
}
Blue Underline
Red Underline
Green Underline
Purple Underline
Current Text Color
Transparent Underline
Each sample uses the same decoration settings except for text-decoration-color. The final sample retains its underline declaration but paints it transparently.
Comparing the Results
| Sample | Decoration Color |
|---|---|
| Blue Underline | #2563eb |
| Red Underline | #dc2626 |
| Green Underline | #059669 |
| Purple Underline | #7c3aed |
| Current Text Color | currentColor |
| Transparent Underline | transparent |
Changing the Text Color
.decoration-color-demo p {
color: #166534;
}
All text becomes green. Only the sample using currentColor automatically changes its decoration color to match.
Changing the Underline Style
.decoration-color-demo p {
text-decoration-style: wavy;
}
All visible underlines become wavy while retaining their assigned colors.
Changing the Thickness
.decoration-color-demo p {
text-decoration-thickness: 5px;
}
All underlines become thicker without changing their colors.
Accessibility Considerations
Decoration colors can improve visual organization, but they should not be the only method used to communicate important information.
Do Not Rely on Color Alone
Different underline colors should not be the only indication of different meanings or states. Provide additional visual or textual cues.
Keep Links Recognizable
Links should remain identifiable as interactive elements. A visible underline is a familiar indicator, particularly within paragraphs.
Maintain Sufficient Contrast
Decoration colors should be distinguishable from the background. Avoid very pale underlines that become difficult to see.
Preserve Keyboard Focus
When decoration colors change on hover, provide an appropriate keyboard focus state as well.
Use Semantic HTML
<p>Original price: <del>$49</del> $39</p>
Semantic elements such as <del> communicate meaning independently of the decoration color.
Avoid Excessively Subtle Decorations
Very thin or low-contrast lines may be difficult to perceive, particularly for users with low vision.
Support High-Contrast Modes
Test decoration colors in forced-colors and high-contrast environments. Ensure the interface remains understandable when colors are adjusted by the browser or operating system.
Respect Reduced Motion Preferences
If decoration colors are animated, consider disabling transitions when users request reduced motion.
Common Mistakes
Expecting the Color to Create an Underline
.example {
text-decoration-color: red;
}
This sets the decoration color but does not create a decoration line. Add text-decoration-line: underline or another line type.
Using a Decoration-Line Keyword
.example {
text-decoration-color: underline;
}
The property accepts color values, not decoration-line keywords.
Using a Decoration Style
.example {
text-decoration-color: dotted;
}
Use text-decoration-style to control the line appearance.
Using a Length Value
.example {
text-decoration-color: 3px;
}
Use text-decoration-thickness to control the line thickness.
Specifying Multiple Colors
.example {
text-decoration-color: red blue;
}
The property accepts one color value. It does not assign separate colors to multiple decoration lines.
Confusing Text Color With Decoration Color
The color property controls the text color. The text-decoration-color property controls the decoration color.
Overwriting the Color With the Shorthand
.example {
text-decoration-color: red;
text-decoration: underline;
}
The shorthand resets the color to currentColor. Set the color afterward or include it in the shorthand.
Assuming the Property Is Inherited
The property is not inherited. Decorations painted by ancestors can propagate visually, but that is different from property inheritance.
Trying to Recolor an Ancestor's Decoration
Changing text-decoration-color on a descendant does not necessarily recolor a decoration introduced by its ancestor.
Using Transparent Decorations Without an Alternative
Making a link underline transparent can reduce discoverability. Keep links recognizable through another accessible visual indicator.
Ignoring Color Contrast
Decoration colors that are too similar to the background may be difficult to perceive.
Ignoring Browser Support for Color Functions
Modern color functions may not be supported by every older browser. Provide a broadly supported fallback color when necessary.
Important Considerations
Keep the following points in mind when using text-decoration-color:
- It controls the color of text decoration lines.
- It applies to underlines, overlines, and strikethroughs.
- It does not create a decoration line by itself.
- The initial value is
currentColor. - The property is not inherited.
- Decorations introduced by ancestors can propagate visually to descendant text.
- It accepts any valid CSS color value.
- Named colors, hexadecimal colors, RGB, and HSL values are supported.
- Modern CSS color functions can also be used when supported by the browser.
- The
currentColorkeyword follows the element's text color. - The
transparentkeyword makes the decoration invisible. - Alpha transparency can be specified through supported color formats.
- The decoration color can differ from the text color.
- One color value applies to the decoration lines introduced by the element.
- The property does not control line style or thickness.
- It is a longhand component of the
text-decorationshorthand. - A later shorthand declaration can reset the decoration color.
- Declaration order matters when combining shorthand and longhand properties.
- The property supports color transitions and animations.
- Changing the decoration color does not normally affect layout dimensions.
- CSS custom properties can be used to manage decoration colors.
- Decoration colors should remain visible against the background.
- Color alone should not communicate important meaning.
- Links should remain recognizable as interactive elements.
- Hover effects should have appropriate keyboard focus behavior.
- Test decoration colors in high-contrast and forced-colors environments.
- Use semantic HTML when decorations represent deleted or changed content.
- Check compatibility when using newer CSS color functions.
Browser Support
The CSS text-decoration-color property is widely available across modern browsers, including Chrome, Edge, Firefox, and Safari.
Support for basic named colors, hexadecimal colors, RGB, HSL, and currentColor is well established. Compatibility with newer CSS color functions depends on the browser and version.
For current compatibility information, visit Can I Use? and search for text-decoration-color.
Basic Compatibility
.example {
text-decoration-line: underline;
text-decoration-color: blue;
}
Basic decoration colors are supported across modern browsers.
Feature Detection
@supports (text-decoration-color: red) {
.example {
text-decoration-color: red;
}
}
This checks whether the browser recognizes the decoration-color declaration.
Fallback for Modern Color Functions
.example {
text-decoration-line: underline;
text-decoration-color: #2563eb;
text-decoration-color: oklch(55% 0.2 260);
}
Browsers that do not recognize oklch() ignore that declaration and retain the hexadecimal fallback.
Testing Recommendations
Test decoration colors with different text colors, backgrounds, link states, and font sizes. Verify that underlines remain visible in high-contrast environments.
Specifications
The text-decoration-color property is defined in the CSS Text Decoration Module Level 3 specification.
CSS Text Decoration Module Level 3 - text-decoration-color Property
The specification defines how decoration colors are selected and applied to text decoration lines.
For additional documentation and examples, consult MDN Web Docs.
