CSS Reference ยท Pseudo-classes
The :visited pseudo-class
Reference for the CSS :visited pseudo-class: style links the user has visited, the privacy restrictions on which properties work, examples and browser support.
The :visited pseudo-class matches links whose address is in the browser's history. It is the classic way to show a reader which articles they have already opened.
Because a stylesheet could otherwise spy on browsing history, browsers deliberately limit what :visited can do. You can change a few colours, and nothing else.
a:visited { color: #7c3aed; }
Try it
Syntax
:visited { /* declarations */ }
No arguments; specificity (0,1,0). Whether a particular link matches depends on the user's own history, which your CSS and JavaScript cannot read.
Syntax and arguments
| Part | Description |
|---|---|
:visited |
Matches links to addresses the browser regards as visited. |
| Allowed properties | Colour-type properties only: color, background-color, border-color (and its sides), outline-color, column-rule-color, text-decoration-color, text-emphasis-color, and SVG fill and stroke. |
| Other properties | Silently ignored in the visited state. |
Usage notes
- Privacy is the reason for the limits. Browsers also report the unvisited style from
getComputedStyle()and may ignore transparency in visited colours, so a script cannot learn which links you visited. - Colour only. You cannot change
display,font-size,contentor add a::beforeicon on visited links only. - Combine with
:linkcarefully. A visited link no longer matches:link. Order rules as:link,:visited,:hover,:active. - Keep sufficient contrast. The visited colour must still be readable on its background; a very pale "visited" grey can be too faint.
- Modern browsers are stricter. Newer browsers further restrict which visits count, for example links visited from another site may not be reported, so do not depend on
:visitedfor essential information.
Browser support
Supported in every browser, always with the privacy restrictions above.
Related
:linkโ unvisited links:any-linkโ any link with an href:hoverโ pointer over the element- Lesson: Pseudo-classes