How to change the color of focused links with CSS

Use the :focus pseudo-class to change the color of focused links. This styling applies when a user clicks on a link or navigates to it using keyboard tabbing. Possible values could be any color name in any valid format.

Syntax

a:focus {
    color: value;
}

Example

You can try to run the following code to implement the color of the focused link −

<!DOCTYPE html>
<html>
<head>
<style>
    a:focus {
        color: #0000FF;
        outline: 2px solid #FF6347;
    }
    
    a {
        color: #333;
        text-decoration: none;
        padding: 10px;
        display: inline-block;
        margin: 10px;
        border: 1px solid #ccc;
    }
</style>
</head>
<body>
    <a href="#">Click me or tab to this link</a>
    <a href="#">Another demo link</a>
</body>
</html>
Two bordered links appear on the page. When you click on a link or navigate to it using the Tab key, the text color changes to blue (#0000FF) and a tomato-colored outline appears around the focused link.

Conclusion

The :focus pseudo-class is essential for accessibility, allowing users to see which link is currently focused. Always ensure sufficient color contrast for focused states.

Updated on: 2026-03-15T11:27:53+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements