Full answer
A link can be in several states at once, and each state has its own pseudo-class.
:linkis an unvisited link, and:visitedis one that is in the history.:hoveris when a pointer is over it.:focusand:focus-visibleapply when it has keyboard focus.:activeis while it is being pressed.
All of these pseudo-classes have the same specificity. When two rules match and both set the same property, the later one wins. A link can be visited and hovered at the same time. If :hover comes before :visited in the file, the visited colour overrides the hover colour for visited links, and the hover seems broken. The usual safe order is LVHA: :link, :visited, :hover, :active. Many people add :focus-visible next to :hover.
A simpler way is to style a for the base look, then a:hover and a:focus-visible, and not use :link at all. The base rule has lower specificity than the pseudo-class rules, so order matters less.
Privacy limits :visited. Browsers allow only a few properties on it, such as colour and border colour, and they report the unvisited value to scripts. This stops sites from finding out your history.
Never remove the focus outline without a replacement. Links should not rely on colour alone. Underline them in text, or give another clue.
At rest the link is blue and underlined. On hover, it is darker blue and the underline gets thicker. With keyboard focus, a ring appears. While pressed, it is red. Because :hover comes after :visited, a visited link also gets the hover colour.
Test with the mouse, with the Tab key, and for visited links in a real browser.
<style>
a { color: #0a58ca; text-decoration: underline; }
a:visited { color: #6f42c1; }
a:hover { color: #003d99; text-decoration-thickness: 3px; }
a:focus-visible { outline: 3px solid #0a58ca; outline-offset: 2px; }
a:active { color: #c00; }
</style>
<p>Read the <a id="a" href="#top">course guide</a> now.</p>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Link state pseudo-classes have the same specificity.
- Use the order :link, :visited, :hover, :active, with :focus-visible near hover.
- :visited allows only a few properties for privacy.
- Do not remove the focus outline.
- Do not rely on colour alone for links.
Common mistakes
- Writing :hover before :visited, so hover does not work on visited links.
- Removing the underline and the focus outline, which leaves keyboard users and colour blind users with no clue.
- Using :focus for mouse clicks and showing a ring that annoys some users, instead of :focus-visible.
Follow-ups
- What does :focus-visible do that :focus does not?
- Why can you only change a few properties on :visited?
Tips
- Say LVHA and explain why: same specificity, so later rules win.
- Mention that :visited has privacy limits on what you can style.