Link Pseudo-Classes (:link, :visited, :any-link)
Anchor elements have their own small family of pseudo-classes for distinguishing links a user hasn't clicked yet from ones they have, on top of the general-purpose :hover, :focus, and :active covered elsewhere.
:link — unvisited links
:link matches an anchor with an href attribute that the browser does NOT consider visited. Anchors without an href (used purely as JS hooks or named fragments) never match :link.
a:link {
color: #2563eb;
text-decoration: underline;
}:visited — visited links
:visited matches a link the browser's history shows the user has already been to.
a:visited {
color: #7c3aed;
}:any-link — a convenient shorthand
:any-link matches an anchor whether it has been visited or not — it's equivalent to :is(:link, :visited), and is handy when you want a base style that applies regardless of visited state, without duplicating the rule.
/* Base styling that should apply no matter the visited state */
a:any-link {
font-weight: 500;
text-decoration: none;
}
/* Then differentiate only what actually needs to differ */
a:link {
color: #2563eb;
}
a:visited {
color: #7c3aed;
}The LVHA order
When styling interactive links, order matters. Because :link, :visited, :hover, and :active can all match the same anchor at different points, and CSS resolves ties between equal-specificity rules by "last one wins," these four rules should always be declared in this order:
a:link {
color: #2563eb;
}
a:visited {
color: #7c3aed;
}
a:hover {
color: #1d4ed8;
}
a:active {
color: #1e3a8a;
}Link — unvisited state, declared first.
Visited — must come after
:linkso a visited link doesn't silently keep the unvisited color.Hover — must come after
:visitedso hovering a visited link still shows the hover color.Active — declared last so the active/pressed color always wins over hover or visited.