Using the CSS :link Pseudo-Class
The :link pseudo-class in CSS is used to style links that have not yet been visited by the user. It targets anchor (<a>) elements that contain an href attribute but remain “unvisited” in the browser history.
Example Usage
css
a:link {
color: blue; /* Unvisited link color */
text-decoration: none; /* Remove underline */
}How It Works
- Targets unvisited links: If the user has not clicked the link before,
:linkstyles apply. - Pairs with
:visitedfor links already clicked. - Order matters: CSS link pseudo-classes follow the LVHA rule:
-
:link -
:visited -
:hover -
:active
-
Example with All Pseudo-Classes
css
a:link {
color: blue;
}
a:visited {
color: purple;
}
a:hover {
color: red;
}
a:active {
color: green;
}Notes
- Only anchors with href are affected.
- Links without
hrefdon’t respond to:linkor:visited.
This pseudo-class helps maintain consistent link styling while distinguishing unvisited vs. visited states to improve UX.