CSS anchor pseudo-classes style links according to their state. The most familiar states are :link, :visited, :hover, and :active.
Basic Example
a:link { color: #0645ad; }
a:visited { color: #6f42c1; }
a:hover { text-decoration: underline; }
a:active { color: #b00020; }
What Each State Means
:linktargets an unvisited link.:visitedtargets a link recorded as visited by the browser.:hoverapplies while a pointing device is over the link.:activeapplies while the link is being activated.:focus-visiblecan provide a clear keyboard-focus indicator.
Recommended Order
The traditional LVHA order—link, visited, hover, active—helps later rules override earlier rules predictably when specificity is equal. Add focus styling so keyboard users can identify the active control.
a:focus-visible {
outline: 3px solid #ffbf47;
outline-offset: 2px;
}
Accessibility Tips
- Do not communicate link state through color alone.
- Use sufficient contrast.
- Keep a visible keyboard-focus indicator.
- Do not remove outlines unless you provide an effective replacement.
- Remember that touch devices may not have a persistent hover state.
Privacy Limitation
Browsers restrict which properties can visibly differ for :visited links to reduce browsing-history exposure. Design visited styles as a helpful enhancement, not a required interaction.