CSS :visited Selector

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Link States

What You’ll Learn

The :visited pseudo-class targets hyperlinks the user has already clicked. Pair it with :link so visitors can tell which pages they have explored and which are still new.

01

Visited

Already clicked.

02

a:visited

Anchor only.

03

:link

Pair together.

04

LVHA

Step two.

05

Privacy

Safe props.

06

Navigation

Track progress.

Introduction

The CSS :visited selector targets links that the user has already visited. It is a pseudo-class that helps differentiate between visited and unvisited hyperlinks, improving navigation and usability on websites.

By applying specific styles to visited links — such as a muted purple color or an underline — you help users track their browsing history and avoid re-reading content they have already seen.

Definition and Usage

Write a:visited to style anchor elements with an href attribute after the browser records that URL in the user’s visit history. Once visited, the link no longer matches :link and instead uses your :visited rules.

💡
Beginner Tip

Always style both :link and :visited. If they look identical, users cannot tell which articles, docs, or menu items they have already opened.

📝 Syntax

The syntax for the :visited pseudo-class is:

syntax.css
a:visited {
  /* CSS properties */
}

The :visited pseudo-class applies only to <a> elements that have an href attribute and are in the visited state.

Basic Example

visited-basic.css
/* Unvisited links */
a:link {
  color: #2563eb;
  text-decoration: none;
}

/* Visited links */
a:visited {
  color: #7c3aed;
  text-decoration: underline;
}
a:visited nav a:visited .resources a:visited

LVHA Declaration Order

1. :link 2. :visited 3. :hover 4. :active

Privacy-Safe Properties

Browsers limit which properties can change on :visited links to protect browsing history. These properties are allowed:

Allowed propertyExample use
colorPurple or muted gray text for visited links
background-colorLight tint behind visited menu items
border-colorSubtle border change on visited cards
outline-colorFocus ring color on visited anchors
text-decoration-colorUnderline color for visited inline links
Not allowed on :visited: Properties like display, visibility, content, font-size, and background-image cannot be used — they could leak which sites a user has visited.

Syntax Rules

  • Only matches <a> elements with an href attribute.
  • Applies after the browser records the URL in the user’s history.
  • Declare after :link and before :hover and :active (LVHA).
  • Stick to privacy-safe color properties for reliable cross-browser results.
  • Pair with :link so unvisited and visited links look distinct.

Related Selectors

  • :link — styles unvisited hyperlinks
  • :hover — styles links while the pointer rests over them
  • :active — styles links while being clicked
  • :focus — styles links when focused via keyboard

⚡ Quick Reference

QuestionAnswer
Selector typeLink pseudo-class
Syntaxa:visited
MatchesVisited <a href> elements
Requireshref attribute on anchor
Declare orderLVHA — :link, :visited, :hover, :active
Styling limitsColor-related properties only (privacy)
Browser supportAll browsers

When to Use :visited

:visited improves hyperlink UX in these scenarios:

  • Article link lists — Show which tutorials or docs the reader has already opened.
  • Documentation sidebars — Mute visited chapter links so new sections stand out.
  • Search results — Help users avoid clicking the same result twice.
  • Resource pages — Track external links the user has already explored.
  • Multi-page guides — Indicate progress through a series of linked lessons.

👀 Live Preview

Click a link below, then return — visited links turn purple and underlined while unvisited links stay blue and bold:

Examples Gallery

Practice :visited with basic styling, navigation menus, resource lists, and privacy-safe color changes.

📜 Core Patterns

Style visited links and pair with :link.

Example 1 — Basic :link and :visited styling

Set blue text for unvisited links and purple underlined text for visited ones.

visited-basic.css
a:link {
  color: #2563eb;
  text-decoration: none;
  font-weight: 700;
}

a:visited {
  color: #7c3aed;
  text-decoration: underline;
}
Try It Yourself

How It Works

After a user clicks a link, the browser switches from a:link to a:visited. The purple color and underline signal that the destination has already been opened.

Example 2 — Visited navigation links

Mute visited menu items with a softer gray while keeping unvisited items dark and bold.

visited-nav.css
nav a:link {
  color: #1e293b;
  text-decoration: none;
  font-weight: 600;
}

nav a:visited {
  color: #94a3b8;
  font-weight: 500;
}

nav a:hover {
  background-color: #e2e8f0;
}
Try It Yourself

How It Works

Scoping to nav a:visited dims only menu links the user has already opened, making fresh sections easier to spot at a glance.

📄 Lists & Privacy

Track reading progress and respect browser security limits.

Example 3 — Tutorial resource list

Style a list of learning links so visited tutorials appear in a muted purple.

visited-resources.css
.resources a:link {
  color: #2563eb;
  text-decoration: none;
}

.resources a:visited {
  color: #9333ea;
  text-decoration: line-through;
  text-decoration-color: #c4b5fd;
}

.resources li {
  margin-bottom: 0.5rem;
}
Try It Yourself

How It Works

Visited tutorials get a muted purple with a light strikethrough, giving readers a visual checklist of lessons they have completed.

Example 4 — Privacy-safe :visited colors only

Use only allowed color properties — browsers ignore layout-changing rules on visited links.

visited-privacy.css
a:link {
  color: #2563eb;
  background-color: transparent;
  border: 1px solid transparent;
}

a:visited {
  color: #6d28d9;
  background-color: #f5f3ff;
  border-color: #ddd6fe;
}
Try It Yourself

How It Works

Browsers allow color, background-color, and border-color on visited links. Properties like width or content are blocked to protect user privacy.

💬 Usage Tips

  • Pair with :link — Always define both unvisited and visited styles together.
  • LVHA order — Place :visited immediately after :link in your stylesheet.
  • Use color contrast — Visited links should still be readable against the page background.
  • Stick to safe properties — Use color, background-color, and border-color for reliable results.
  • Scope when needed — Use nav a:visited or .sidebar a:visited for targeted menus.

⚠️ Common Pitfalls

  • Identical :link and :visited styles — Users cannot tell which pages they have already opened.
  • Blocked propertiesfont-size, display, content, and background-image do not work on :visited links.
  • Wrong LVHA order — Declaring :hover before :visited can prevent hover styles from appearing on visited links.
  • Missing href:visited does not apply to <a> elements without an href attribute.
  • Cache confusion — Browser history can make a link appear visited even if the user did not click it recently; clearing history resets the state.

♿ Accessibility

  • Do not rely on color alone — Combine color changes with underline, weight, or icons (on the unvisited state) for clarity.
  • Maintain contrast — Visited link colors must still meet WCAG AA contrast ratios (4.5:1 for normal text).
  • Focus indicators — Add :focus-visible styles so keyboard users can navigate links.
  • Meaningful link text — Describe the destination; visited state is a bonus cue, not a replacement for clear labels.
  • Cognitive support — Visited styling helps users with memory challenges track what they have already read.

🧠 How :visited Works

1

User clicks a link

The browser navigates to the URL and records it in local visit history.

Click
2

State changes to visited

On return visits, the anchor no longer matches :link.

State
3

:visited styles apply

Only privacy-safe properties like color and background-color take effect.

Style
=

Browsing context

Users see which links are fresh and which they have already explored.

🖥 Browser Compatibility

The :visited pseudo-class is supported in all modern browsers. Privacy restrictions on allowed properties are enforced consistently.

Baseline · Universal support

Visited link styling everywhere

:visited works reliably in Chrome, Firefox, Safari, Edge, and Opera with privacy-safe property limits.

99% Universal support
Google Chrome All versions · Privacy limits enforced
Full support
Mozilla Firefox All versions · Privacy limits enforced
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
:visited pseudo-class 99% supported

Bottom line: :visited is safe for all hyperlink visited-state styling; use only color-related properties for cross-browser consistency.

🎉 Conclusion

The CSS :visited selector is a simple yet effective way to style visited links, helping users distinguish between pages they have already explored and those they have not.

While browser security measures limit which properties can be applied, the selector still plays an important role in enhancing website navigation and user experience. Pair it with :link, :hover, and :active in LVHA order for a complete link styling system.

💡 Best Practices

✅ Do

  • Style :link and :visited differently
  • Follow LVHA declaration order
  • Use privacy-safe color properties
  • Ensure sufficient contrast for visited colors
  • Add :focus-visible for keyboard users

❌ Don’t

  • Use display, content, or font-size on :visited
  • Make visited links invisible or unreadable
  • Put :hover before :visited in CSS
  • Rely on color alone for link identification
  • Forget the href attribute on anchors

Key Takeaways

Knowledge Unlocked

Five things to remember about :visited

Use these points when styling visited hyperlinks.

5
Core concepts
a 02

a:visited

Needs href.

Syntax
LVHA 03

Step 2

After :link.

Order
🔒 04

Privacy

Colors only.

Security
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

The :visited pseudo-class matches anchor elements with an href attribute that the user has already visited. It lets you style clicked hyperlinks differently from unvisited ones so users can track where they have been.
:visited only applies to a elements that have an href attribute and are in the visited state. It does not match buttons, spans, or anchors without href.
Browsers restrict which CSS properties can change on :visited links to prevent websites from fingerprinting a user's browsing history. Only color-related properties like color, background-color, and border-color are allowed.
Declare :link first, then :visited, then :hover, then :active. This LVHA order prevents later states from being overridden incorrectly in the cascade.
Yes. All modern browsers support :visited for hyperlink styling. The privacy restrictions on allowed properties are also enforced consistently across Chrome, Firefox, Safari, and Edge.

Practice in the Live Editor

Open the HTML editor and experiment with :visited, :link, and the full LVHA link state stack.

HTML Editor →

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.

5 people found this page helpful