Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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.
Advertisements
