How to Change Link Underline Color using text-decoration-color CSS?

The CSS text-decoration-color property is used to change the color of text decorations like underlines, overlines, and line-through effects. For links, this property allows you to customize the underline color independently from the text color.

Syntax

selector {
    text-decoration-color: value;
}

Possible Values

Value Description
color-name Sets the color using predefined names like red, blue, orange
hex-value Sets the color using hexadecimal values like #FF5733
rgb() Sets the color using RGB values like rgb(255, 87, 51)
inherit Inherits the color from the parent element
currentColor Uses the current text color as decoration color

Example: Basic Link Underline Color

The following example demonstrates how to change the link underline color using different color values −

<!DOCTYPE html>
<html>
<head>
<style>
    .orange-underline {
        text-decoration: underline;
        text-decoration-color: orange;
        color: #333;
    }
    
    .red-underline {
        text-decoration: underline;
        text-decoration-color: #FF0000;
        color: #333;
    }
    
    .blue-underline {
        text-decoration: underline;
        text-decoration-color: rgb(0, 100, 255);
        color: #333;
    }
</style>
</head>
<body>
    <h1>Link Underline Color Examples</h1>
    <p>Access our <a href="/java" class="orange-underline">Java Tutorial</a> for free</p>
    <p>Access our <a href="/python" class="red-underline">Python Tutorial</a> for free</p>
    <p>Access our <a href="/css" class="blue-underline">CSS Tutorial</a> for free</p>
</body>
</html>
Three links appear with dark gray text but different colored underlines: orange, red, and blue respectively. Each link maintains its own distinct underline color while keeping the text color consistent.

Example: Hover Effects

You can also combine text-decoration-color with hover effects to create interactive links −

<!DOCTYPE html>
<html>
<head>
<style>
    .hover-link {
        text-decoration: underline;
        text-decoration-color: lightgray;
        color: #2c5aa0;
        transition: text-decoration-color 0.3s ease;
    }
    
    .hover-link:hover {
        text-decoration-color: #ff6b35;
    }
</style>
</head>
<body>
    <h1>Interactive Link Example</h1>
    <p>Hover over this <a href="/tutorials" class="hover-link">tutorial link</a> to see the underline color change.</p>
</body>
</html>
A blue link with a light gray underline appears. When hovered, the underline smoothly transitions to an orange color while the text remains blue.

Conclusion

The text-decoration-color property provides fine control over link styling by separating text color from underline color. This allows for more creative and accessible link designs while maintaining readability.

Updated on: 2026-03-15T15:24:19+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements