# :visited

> The `:visited` CSS pseudo-class selects links the user has already visited, styling anchor elements whose `href` URL matches one in the browser history.

## Why can't I change some styles with the CSS :visited selector?

The pseudo-class that styles links that have been visited by the user. It allows for different visual cues for links that have been clicked before, such as changing the color to indicate the link's history.

- Topic: Pseudo Classes
- Type: pseudo-class
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 1+, Safari iOS 1+

## Example

Wrong:

```css
a:visited {
  font-weight: normal;
  opacity: 0.6;
}
```

Right:

```css
a:visited {
  color: #6b3fa0;
}
```

Browsers allow only color changes on `:visited`, so sites can't detect browsing history through layout.

## Common mistakes

- Setting `display`, `font-weight` or a background image in `:visited` and seeing no change.
- Using a transparent color in `:visited`, while the alpha part is ignored for privacy.

## Key points

- `:visited` rules only change colors, like `color`, `background-color` and `border-color`.
- Code does not read `:visited` styles with `getComputedStyle()`, which reports unvisited values.
- Visited links keep enough contrast against the background, like other text.

## Interview questions

### Why is :visited limited to colors?

To protect privacy. If layout could change, scripts could measure it and learn which sites the user has visited.

### Can JavaScript detect visited links?

No. `getComputedStyle()` returns the unvisited style, so the visited state can't be read.

### Where should :visited go in my link styles?

After `:link` and before `:hover` and `:active`, so hover still works on visited links.

## Related cards

- [:link](https://wonderium.dev/css/link.md)
- [:hover](https://wonderium.dev/css/hover.md)
- [`<a>`](https://wonderium.dev/html/a.md)
- [link](https://wonderium.dev/a11y/link.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/visited
- Last updated: 2026-11-25
