Highlight visited links — and why CSS allows so little
Search results, an article list, documentation — and no way to tell which links you have already opened. One CSS rule fixes that. And along the way it is worth learning why the :visited selector is so oddly trimmed down.
The rule
In the rule's CSS tab, URL pattern for a page with link lists or * globally:
a:visited {
color: #9333ea !important;
}
That is all. Visited links turn purple. Pick a color strongly different from the normal link color so the contrast reads instantly.
Why so little is possible
The natural instinct: if I can change the color, I will add an icon or a background too. You will not — and that is deliberate.
If :visited allowed arbitrary styles, any page could detect your history. It would insert a thousand hidden links, give each a different size or background via :visited, measure the layout with JavaScript and read which URLs you had visited. That was a real vulnerability (history sniffing) — and browsers closed it.
What is allowed, what is not
On :visited only color properties work: color, background-color, border-color, outline-color. And even those are "lied about" in one direction:
- No layout properties.
display,font-size,content,visibility— ignored on:visited. That is whya:visited::after { content: " ✓" }will not work. - getComputedStyle lies. Asked for the color of a visited link, it returns the unvisited color — so JavaScript cannot read the truth.
- Background and border must be visible beforehand. You can change the color of a background, but you cannot "turn it on" from nothing in a measurable way.
Want more than color?
Badges, icons, visit counters — :visited will not give you those. They would require tracking your history in JavaScript, which is a separate, much heavier topic. For most cases the color alone is plenty — because the only thing you really need is "have I been here or not".
Pitfalls
- Exact-URL matching.
:visitedworks if you visited exactly that address. A link to/articlewill not light up if you were on/article?ref=x. - SPAs and links. In a single-page app a "navigation" can be a state change without real navigation — the browser then records no history entry and
:visiteddoes not apply. - Contrast. Purple on a white background is readable; on a dark theme pick a lighter shade.
See also
- Examples — this snippet and other ready-made CSS
- Dark mode for any website — another comfort-focused CSS rule
- Hide cookie banners — CSS-based page decluttering
Install JustZix — and tell at a glance where you have already been.
Rate this post
No ratings yet — be the first.