← All posts

Tutorials

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:

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

See also

Install JustZix — and tell at a glance where you have already been.

Rate this post

No ratings yet — be the first.

Try it yourself

Install JustZix and paste any snippet from this article. Two minutes from zero to a working rule across all your devices.

Get JustZix

Features · How it works · Examples · Use cases