Home CSS Selectors :visited CSS :visited Pseudo-Class Definition
Definition and Usage :visited styles a link after the user has visited its URL. It applies only to <a> and <area> elements that have an href.
Pair it with :link for unvisited links, and keep LVHA order : :link → :visited → :hover → :active.
Privacy Style limitsBrowsers allow mainly color-related properties on :visited (for example color, background-color, border-*-color, text-decoration-color). Size, layout, and display changes are blocked.
Note Set a non-transparent base firstProperties like background-color need a non-transparent default outside :visited, or the visited style may not show.
Syntax
CSS Syntax Common form: a:visited { color: …; }.
Patterns
Selector Patterns Pattern Description Try it a:visitedChange color of visited links Try ita:visited + base bgBackground and border colors (with defaults) Try itLVHA order :link, :visited, :hover, :active Try it:link vs :visitedUnvisited vs visited (mutually exclusive) Try it
Approach
How to Use :visited Style unvisited links first, then visited ones, then hover/active.
Use real <a href="…"> links. Write a:link (optional) then a:visited. Change only allowed color properties. Add :hover and :active after :visited. Piece Required? Role <a href> / <area href>Yes Only these can be visited links :visitedYes Matches after the URL is in history Color properties Yes (practical) What browsers allow you to change LVHA order Recommended Keeps hover/active working as expected
Try it
Live Preview Visited links turn forest green via a:visited. Whether a URL looks visited depends on your browser history—click a link, then come back to see the change.
Code
CSS Examples Each snippet focuses on :visited. Use Try It Yourself for a live editor.
1. Visited color 2. Background colors 3. LVHA order Example 1 — Change Visited Link Color Give visited links a distinct text color (MDN-style).
a:visited {
color: forestgreen;
text-decoration-color: hotpink;
} If the link is in history, you should see forest green text.
How It Works Target visited anchors. a:visited matches opened URLs.Set color. Text turns forest green.Tint the underline. text-decoration-color is an allowed property.Respect history. Unvisited URLs keep the default/unvisited style.Example 2 — Background and Border Colors Give non-transparent defaults first, then change them for visited links.
a {
background-color: white;
border: 1px solid white;
}
a:visited {
background-color: yellow;
border-color: hotpink;
color: hotpink;
} Without the white defaults, background/border visited styles often fail.
How It Works Set base colors. White background and border create a changeable starting point.Style :visited. Switch to yellow / hotpink colors.Stay in the allowlist. Only color channels change—not width or padding.Alpha is limited. Browsers reuse the non-visited alpha component for privacy.Example 3 — LVHA Order Declare link states in cascade-friendly order.
a:link {
color: blue;
}
a:visited {
color: purple;
}
a:hover {
color: darkorange;
}
a:active {
color: red;
} Hover/active come after visited so they can still override while interacting.
How It Works Start with :link. Unvisited default color.Add :visited. History color without blocking hover later.Place :hover next. Equal specificity means source order wins.Finish with :active. Press feedback stays visible while clicking. Edge Cases & Pitfalls Privacy rules explain most “:visited CSS is broken” reports.
privacy Only certain colors work Font size, padding, display, and similar properties on :visited are ignored. Stick to the color allowlist.
js getComputedStyle liesScripts always see the non-visited color. querySelector(":visited") also returns nothing usable for history sniffing.
href Needs href Anchors without href are not links for this purpose. The HTML <link> element never matches :visited.
order Wrong LVHA order hides hover If :visited comes after :hover with equal specificity, visited links may not show hover styles correctly.
contrast Keep contrast readable Purple-on-dark or low-contrast visited colors hurt accessibility. Check both visited and unvisited states.
Compatibility
Browser Support :visited is a browser CSS pseudo-class . Node.js, Deno, and Bun do not evaluate it.
✓ Baseline · Widely available
:visited Supported everywhere for decades. Privacy restrictions on which properties apply are also enforced in all major browsers.
Google Chrome All
Full
Mozilla Firefox All
Full
Apple Safari All
Full
Microsoft Edge All
Full
Opera All
Full
Samsung Internet All
Full
Internet Explorer All
Full a:visited Universally supported
Bottom line: Production-ready. Expect color-only styling and LVHA order for predictable link states.
Remember
Key Takeaways Role: style links whose URL is already in the user’s history.
Limits: mainly color properties; privacy blocks layout tricks.
Order: LVHA — link, visited, hover, active.
Tip: set non-transparent defaults before styling visited backgrounds.
One line: a:visited recolors opened links—within privacy limits.
Frequently Asked Questions What does :visited do? It styles an <a> or <area> with an href after the user has visited that URL.
Which elements match :visited? Only <a> and <area> elements that have an href. Link without href, and elements like <link>, never match.
Why can’t I change font-size on :visited? Browsers limit :visited to certain color-related properties for privacy, so sites cannot easily read browsing history.
What is LVHA order? Declare :link, then :visited, then :hover, then :active so later interaction states can override correctly.
Are :link and :visited mutually exclusive? Yes. An unvisited link matches :link; a visited one matches :visited—not both at once.
Is :visited a runtime API? No. It is a browser CSS pseudo-class, not a Node.js feature.
Next: :hover Learn how to style elements while the pointer is over them.
:hover tutorial → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion