CSS :visited Pseudo-Class

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

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 limits

Browsers 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 first

Properties like background-color need a non-transparent default outside :visited, or the visited style may not show.

CSS Syntax

syntax.css
:visited { … }

Common form: a:visited { color: …; }.

Selector Patterns

PatternDescriptionTry it
a:visitedChange color of visited linksTry it
a:visited + base bgBackground and border colors (with defaults)Try it
LVHA order:link, :visited, :hover, :activeTry it
:link vs :visitedUnvisited vs visited (mutually exclusive)Try it

How to Use :visited

Style unvisited links first, then visited ones, then hover/active.

  1. Use real <a href="…"> links.
  2. Write a:link (optional) then a:visited.
  3. Change only allowed color properties.
  4. Add :hover and :active after :visited.
PieceRequired?Role
<a href> / <area href>YesOnly these can be visited links
:visitedYesMatches after the URL is in history
Color propertiesYes (practical)What browsers allow you to change
LVHA orderRecommendedKeeps hover/active working as expected

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.

:visited demo

Empty href="" counts as the current page (usually already visited).

Visited preview

Rule used: .tut-vst-stage a:visited { color: forestgreen; }

CSS Examples

Each snippet focuses on :visited. Use Try It Yourself for a live editor.

Example 1 — Change Visited Link Color

Give visited links a distinct text color (MDN-style).

CSS
a:visited {
  color: forestgreen;
  text-decoration-color: hotpink;
}
Try It Yourself

How It Works

  1. Target visited anchors. a:visited matches opened URLs.
  2. Set color. Text turns forest green.
  3. Tint the underline. text-decoration-color is an allowed property.
  4. 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.

CSS
a {
  background-color: white;
  border: 1px solid white;
}

a:visited {
  background-color: yellow;
  border-color: hotpink;
  color: hotpink;
}
Try It Yourself

How It Works

  1. Set base colors. White background and border create a changeable starting point.
  2. Style :visited. Switch to yellow / hotpink colors.
  3. Stay in the allowlist. Only color channels change—not width or padding.
  4. Alpha is limited. Browsers reuse the non-visited alpha component for privacy.

Example 3 — LVHA Order

Declare link states in cascade-friendly order.

CSS
a:link {
  color: blue;
}

a:visited {
  color: purple;
}

a:hover {
  color: darkorange;
}

a:active {
  color: red;
}
Try It Yourself

How It Works

  1. Start with :link. Unvisited default color.
  2. Add :visited. History color without blocking hover later.
  3. Place :hover next. Equal specificity means source order wins.
  4. 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 lies

Scripts 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.

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.

99% All modern 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.

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

It styles an <a> or <area> with an href after the user has visited that URL.
Only <a> and <area> elements that have an href. Link without href, and elements like <link>, never match.
Browsers limit :visited to certain color-related properties for privacy, so sites cannot easily read browsing history.
Declare :link, then :visited, then :hover, then :active so later interaction states can override correctly.
Yes. An unvisited link matches :link; a visited one matches :visited—not both at once.
No. It is a browser CSS pseudo-class, not a Node.js feature.

Next: ::after Pseudo-Element

Continue through the CSS tutorial reference.

::after Pseudo-Element tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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