The :visited
CSS pseudo-class represents links that the user has already visited. For privacy reasons, the styles that can be modified using this selector are very limited.
/* Selects any <a> that has been visited */ a:visited { color: green; }
Styles defined by the :visited
pseudo-class will be overridden by any subsequent link-related pseudo-class (:link
, :hover
, or :active
) that has at least equal specificity. To style links appropriately, put the :visited
rule after the :link
rule but before the :hover
and :active
rules, as defined by the LVHA-order: :link
— :visited
— :hover
— :active
.
For privacy reasons, browsers strictly limit which styles you can apply using this pseudo-class, and how they can be used:
color
, background-color
, border-color
, border-bottom-color
, border-left-color
, border-right-color
, border-top-color
, column-rule-color
, and outline-color
.fill
and stroke
.:visited
state will be used instead, except when that component is 0
, in which case the style set in :visited
will be ignored entirely.window.getComputedStyle
method will lie and always return the value of the non-:visited
color.Note: For more information on these limitations and the reasons behind them, see Privacy and the :visited selector.
:visited
Properties that would otherwise have no color or be transparent cannot be modified with :visited
. Of the properties that can be set with this pseudo-class, your browser probably has a default value for color
and column-rule-color
only. Thus, if you want to modify the other properties, you'll need to give them a base value outside the :visited
selector.
<a href="#test-visited-link">Have you visited this link yet?</a><br> <a href="">You've already visited this link.</a>
a { /* Specify non-transparent defaults to certain properties, allowing them to be styled with the :visited state */ background-color: white; border: 1px solid white; } a:visited { background-color: yellow; border-color: hotpink; color: hotpink; }
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of ':visited' in that specification. | Living Standard | |
Selectors Level 4 The definition of ':visited' in that specification. | Working Draft | No change. |
Selectors Level 3 The definition of ':visited' in that specification. | Recommendation | No change. |
CSS Level 2 (Revision 1) The definition of ':visited' in that specification. | Recommendation | Lifts the restriction to only apply :visited to the <a> element. Lets browsers restrict its behavior for privacy reasons. |
CSS Level 1 The definition of ':visited' in that specification. | Recommendation | Initial definition. |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 1 | Yes | 1 | Yes | 3.5 | 1 |
Restrict CSS properties allowed in a statement using :visited for privacy |
6 | Yes | 4 | 8 | ? | 5 |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | Opera Android | iOS Safari | Samsung Internet |
---|---|---|---|---|---|---|---|
Basic support | 4.4 | ? | Yes | 4 | 37 | 9.3 | ? |
Restrict CSS properties allowed in a statement using :visited for privacy |
? | ? | ? | ? | ? | ? | ? |
:link
, :active
, :hover
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/:visited