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
.
Privacy restrictions
For privacy reasons, browsers strictly limit which styles you can apply using this pseudo-class, and how they can be used:
- Allowable CSS properties are
color
,background-color
,border-color
,border-bottom-color
,border-left-color
,border-right-color
,border-top-color
,column-rule-color
,outline-color
,text-decoration-color
, andtext-emphasis-color
. - Allowable SVG attributes are
fill
andstroke
. - The alpha component of the allowed styles will be ignored. The alpha component of the element's non-
:visited
state will be used instead, except when that component is0
, in which case the style set in:visited
will be ignored entirely. - Although these styles can be change the appearance of colors to the end user, the
window.getComputedStyle
method will lie and always return the value of the non-:visited
color. - The
<link>
element is never matched by:visited
.
Note: For more information on these limitations and the reasons behind them, see Privacy and the :visited selector.
Syntax
:visited
Examples
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.
HTML
<a href="#test-visited-link">Have you visited this link yet?</a><br>
<a href="">You've already visited this link.</a>
CSS
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;
}
Result
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living StandardThe definition of ':visited' in that specification. | Living Standard | |
Selectors Level 4The definition of ':visited' in that specification. | Working Draft | No change. |
Selectors Level 3The 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 1The definition of ':visited' in that specification. | Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
:visited
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 4 |
Opera
Full support 3.5 |
Safari
Full support 1 |
WebView Android
Full support 4.4 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
:visited no longer matches <link> elements
|
Chrome Full support 1 Full support 1 Notes' Chromium has never matched |
Edge
Full support 12 |
Firefox
Full support 70 |
IE
No support No |
Opera Full support 15 Full support 15 Notes' Chromium has never matched |
Safari
Full support 12 |
WebView Android Full support 4.4 Full support 4.4 Notes' Chromium has never matched |
Chrome Android Full support 18 Full support 18 Notes' Chromium has never matched |
Firefox Android
No support No |
Opera Android Full support 14 Full support 14 Notes' Chromium has never matched |
Safari iOS
Full support 12 |
Samsung Internet Android Full support 1.0 Full support 1.0 Notes' Chromium has never matched |
Restrict CSS properties allowed in a statement using :visited for privacy
|
Chrome
Full support 6 |
Edge
Full support 12 |
Firefox
Full support 4 |
IE
Full support 8 |
Opera
Full support 15 |
Safari
Full support 5 |
WebView Android
Full support 37 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 14 |
Safari iOS
Full support 4.2 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.'
- See implementation notes.
See also
- Privacy and the :visited selector
- Link-related pseudo-classes:
:link
,:active
,:hover
:visited by Mozilla Contributors is licensed under CC-BY-SA 2.5.