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
Usage of :visited pseudo-class in CSS
The :visited pseudo-class is used to add special styling to links that have already been visited by the user. This allows you to provide visual feedback indicating which links have been previously clicked.
Syntax
a:visited {
property: value;
}
Possible Values
| Property | Description |
|---|---|
color |
Changes the text color of visited links |
background-color |
Changes the background color of visited links |
text-decoration |
Adds or removes underlines, strikethrough, etc. |
Example
The following example changes the color of visited links to green −
<!DOCTYPE html>
<html>
<head>
<style>
a:link {
color: #0066cc;
text-decoration: none;
}
a:visited {
color: #006600;
text-decoration: underline;
}
a:hover {
color: #ff6600;
}
</style>
</head>
<body>
<h3>Link States Demo</h3>
<p><a href="https://www.tutorialspoint.com">Visit TutorialsPoint</a></p>
<p><a href="https://www.example.com">Visit Example Site</a></p>
<p><em>Click the links above to see the visited state styling.</em></p>
</body>
</html>
Two links appear in blue. After clicking a link, it will turn green with an underline to indicate it has been visited. Hovering over any link changes its color to orange.
Key Points
Privacy Restrictions: Due to security concerns, browsers limit which CSS properties can be modified for visited links. Only color-related properties like color, background-color, and border-color are typically allowed.
Order Matters: The :visited selector should be placed after :link but before :hover and :active in your CSS for proper cascade behavior.
Conclusion
The :visited pseudo-class is essential for improving user experience by showing which links have been previously accessed. Remember that browser security restrictions limit the styling options available for visited links.
