:visited
Example
a:visited {
font-weight: normal;
opacity: 0.6;
}a:visited {
color: #6b3fa0;
}Browsers allow only color changes on :visited, so sites can't detect browsing history through layout.
Common mistakes
- Setting
display,font-weightor a background image in:visitedand seeing no change. - Using a transparent color in
:visited, while the alpha part is ignored for privacy.
Key points
:visitedrules only change colors, likecolor,background-colorandborder-color.- Code does not read
:visitedstyles withgetComputedStyle(), which reports unvisited values. - Visited links keep enough contrast against the background, like other text.
Interview questions
Why is :visited limited to colors?
To protect privacy. If layout could change, scripts could measure it and learn which sites the user has visited.
Can JavaScript detect visited links?
No. getComputedStyle() returns the unvisited style, so the visited state can't be read.
Where should :visited go in my link styles?
After :link and before :hover and :active, so hover still works on visited links.