On this page
CSS can style a link differently after a browser considers it visited. That visual distinction has led to a misconception: that a website can use :visited to read and export a visitor’s browsing history. Modern browsers restrict what pages can learn from visited-link styling, so that technique is not a dependable history-reading method.
This article explains the privacy risk and provides a local page you can use to investigate the behavior in your own browsers. The current MDN :visited and browser privacy documentation could not be consulted for this article, and the example was not run in any browser here. Check those sources and test your target browsers before relying on implementation-specific behavior.
Key Takeaways
:visitedis intended to provide a visual cue to the person viewing a page, not an API for websites to access browsing history.- Browsers restrict visited-link styling and what scripts can observe through style inspection. The exact behavior can depend on the browser and its privacy settings.
- A site can still learn about interactions it receives itself, such as a click that navigates to its server. That is different from reading the browser’s general history.
- The local example below is a diagnostic exercise, not evidence that a particular browser version has been verified.
Why visited links are a privacy concern
Imagine a page containing links to many sensitive topics or services. If its script could reliably determine which links were visited, it could infer information about a person without that person intentionally sharing it. The page would only need to guess destinations; it would not need access to a history export.
A CSS rule such as a:visited { color: purple; } can make a visited link look different to the user. The privacy boundary is that the page should not be able to turn that difference into a reliable list of visited URLs.
Browsers therefore limit which visual properties can differ for visited links and restrict script-facing observations. For example, layout-changing differences would be useful to a page attempting to measure which links were visited, so developers should not assume that arbitrary CSS properties can be used with :visited.
Advertisement
CSS visited link privacy restrictions in practice
The intended distinction is between rendering and inspection. A browser may display an allowed visited-link color while exposing a privacy-protected value when JavaScript asks for the link’s computed style. Seeing a different color on screen does not mean that getComputedStyle() gives the page the actual displayed color.
Restrictions also mean that a :visited rule is not a general-purpose way to change layout, load different resources, or signal a link’s history state to a script. Browser implementations and privacy protections can change; this article does not verify the exact property allowlists or inspection behavior of any current version.
Even the visual cue is not a complete record of where someone has been. History settings, private browsing, cleared history, and browser privacy measures can affect whether a link is treated as visited. Absence of visited styling is not proof that a person never opened the destination.
Try a local comparison
This small page lets you compare what you see with what the page’s script can read. It requires Python and a browser. The code is illustrative and has not been executed for this article.
Create a directory with these two files. First, save this as index.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Visited-link privacy experiment</title>
<style>
a:link { color: #0057b8; }
a:visited { color: #9b1c1c; }
</style>
</head>
<body>
<h1>Visited-link privacy experiment</h1>
<p><a id="target" href="visited.html">Open the local test page</a></p>
<p>Return here using your browser’s Back button, then inspect the link.</p>
<button id="inspect" type="button">Read computed color</button>
<p id="result" aria-live="polite"></p>
<script>
const link = document.getElementById('target');
const result = document.getElementById('result');
document.getElementById('inspect').addEventListener('click', () => {
result.textContent = `Script-visible color: ${getComputedStyle(link).color}`;
});
</script>
</body>
</html>
Save this as visited.html in the same directory:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Local test destination</title>
</head>
<body>
<p>This is the local destination. Use your browser’s Back button to return.</p>
</body>
</html>
From that directory, start a local server:
python3 -m http.server 8000 --bind 127.0.0.1
- Open
http://127.0.0.1:8000/in a browser. Note the link’s displayed color and click Read computed color. - Open the link, then use the browser’s Back button. Compare its displayed color with the value shown after clicking Read computed color again.
- Repeat in a second browser, such as Firefox or Chrome. Record each browser’s name, version, operating system, and relevant history or private-browsing settings along with your observations.
- Stop the server with Ctrl+C when finished.
The expected diagnostic distinction is that a link may appear in the visited color while the script-visible computed color remains the unvisited color. Do not assume every setup will show a visual change: the browser may not retain or expose a visited state under the conditions you chose. If the destination was already visited, a fresh test profile or a different local destination filename can help establish a baseline.
Verification limit: No browsers or versions were tested for this article, and no observed results are being reported. A local result describes only the browser version and settings used for that test; it does not establish the behavior of every browser or future release.
Advertisement
What a site can still learn
Visited-link protections do not make browsing anonymous. A website can record a request when you navigate to a page it controls, and its own scripts may observe interactions on that site. A destination can also receive information associated with a navigation, depending on browser behavior and site policy.
Those observations are not equivalent to exporting a visitor’s browsing history. Nor should :visited restrictions be treated as a guarantee against every possible tracking method or browser vulnerability.
Common Mistakes
- Treating a visual color as script-readable data. A browser can render a difference while protecting style inspection.
- Testing only one browser and generalizing. Record versions and settings, and repeat the experiment in the environments relevant to your users.
- Assuming no visited color means no visit occurred. History and privacy settings can affect the result.
- Using visited state for application logic. It is not a reliable substitute for explicit application state or user consent.
Best Practices
Use :visited as a visual navigation aid, not as a source of analytics or authorization decisions. Choose link colors that remain distinguishable and readable, and do not rely on color alone to convey important information.
When evaluating privacy claims, separate what a person can see on screen from what a page can programmatically observe. Test locally, document the browser versions and settings, and consult the current browser and MDN documentation for the details applicable to your project.
Conclusion
CSS visited-link styling can help users recognize links, but browser privacy restrictions prevent it from being a dependable method for reading or exporting someone’s browsing history. A local comparison can illustrate the boundary; its results should be interpreted in the context of the browser and settings used.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.