CSS - :visited

The :visited CSS pseudo-class lets you select only links that have been visited. This style may be overridden by any other link-related pseudo-classes, that is :link, :hover, and :active, appearing in subsequent rules. In order to style appropriately links, you need to put the :visited rule after the :link rule but before the other ones, defined in the LVHA-order: :link:visited:hover:active.

Example

 

CSS
a:visited { color: #4b2f89; }
a:visited { background-color: white } 

Syntax  

CSS
:visited <a title="Curly braces" href="css/value_definition_syntax#curly_braces_(.7b_.7d)">{</a> <var>style properties</var> <a title="Curly braces" href="css/value_definition_syntax#curly_braces_(.7b_.7d)">}</a>

Description  

The :visited CSS pseudo-class lets you select only links that have been visited. This style may be overridden by any other link-related pseudo-classes, that is :link, :hover, and :active, appearing in subsequent rules. In order to style appropriately links, you need to put the :visited rule after the :link rule but before the other ones, defined in the LVHA-order: :link:visited:hover:active.

Note: For privacy reasons, browsers strictly limit the styles you can apply using an element selected by this pseudo-class: only color, background-color, border-color, border-bottom-color, border-left-color, border-right-color, border-top-color, outline-color, column-rule-color, fill and stroke. Note also that the alpha component will be ignored: the alpha component of the not-visited rule is used instead (except when the opacity is 0, in that case the whole color is ignored, and the one of the not-visited rule is used).

Though the color can be changed, the method getComputedStyle will lie and always give back the value of the non-visited color.

For more information on the limitations and the motivation for them, see Privacy and the :visited selector.

Browser Compatibility  

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.7 or earlier) 3.5 3.5 1.0
Restrictions in CSS properties allowed in a statement using :visited 6 4.0 (2.0) 8 (or earlier) ? 5.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support ? 1.0 (1.0) ? ? ?

See Also  

Specifications  

Specification Status Comment
WHATWG 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 Lift the restriction to only apply it for <a> element. Let browsers restricts its behavior for privacy reasons.
CSS Level 1
The definition of ':visited' in that specification.
Recommendation Initial definition.

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/css/:visited

CSS CSS Pseudo-class CSS3 Layout NeedsMobileBrowserCompatibility Reference Référence Web