Originally, the CSS :visited
selector was a privacy and security risk. With a little bit of JavaScript, websites could uncover a user's browsing history and figure out what sites the user had visited. This was done using methods like window.getComputedStyle
and other techniques. This process was quick, enabling websites to not only determine where the user had been on the web, but also to guess a lot of information about the user's identity.
To mitigate this privacy concern, browsers limit the amount of information that can be obtained from visited links.
Little white liesTo preserve users' privacy, browsers lie to web applications under certain circumstances:
window.getComputedStyle
method and similar functions, such as element.querySelector
, always return values indicating that a user has never visited any of the links on a page.:visited + span
, the adjacent element (span
in this example) is styled as though the link were unvisited.You can style visited links, but there are limits to which styles you can use. Only the following styles can be applied to visited links:
color
background-color
border-color
(and its sub-properties)column-rule-color
outline-color
text-decoration-color
text-emphasis-color
fill
and stroke
attributesIn addition, even for the styles mentioned above, transparency differences between unvisited and visited links are not applied. This restriction prevents the use of the alpha
parameter in various <color>
functions or the transparent
keyword to distinguish between the two states.
Here is an example of how to use styles with the aforementioned restrictions:
:link {
outline: 1px dotted blue;
background-color: white;
/* The default value of `background-color` is `transparent`. You need to
specify a different value, otherwise changes on `:visited` won't apply. */
}
:visited {
outline-color: orange; /* Visited links have an orange outline */
background-color: green; /* Visited links have a green background */
color: yellow; /* Visited links have yellow colored text */
}
Impact on web developers
You may want to consider the following when developing sites:
background-image
values based on a link's visited state will not work since only colors can be used to style visited links.:visited
selector.RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4