CSS Portal

:visited CSS Pseudo Class

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
:visited
CSS Pseudo ClassThis pseudo class is supported by all modern browsers.
Updated 31st December 2025

Description

The :visited pseudo-class in CSS is used to style links that the user has previously visited. It applies specifically to anchor elements that have an href attribute and whose URLs are present in the browser’s history. This pseudo-class allows developers to visually distinguish links that have been interacted with, providing users with contextual information about which links they have already explored.

A key consideration with :visited is privacy. Browsers limit the styles that can be applied to visited links to prevent history-sniffing attacks. Typically, only the following properties are safely allowed: color, background-color, border-color, and some text decoration properties. Properties such as position, width, height, and content are ignored for visited links for security reasons.

Using :visited alongside other pseudo-classes like :hover or :active can create interactive link effects. For example, you can have a link change color when hovered over, but only if it has been visited:

<a href="https://example.com">Example Link</a>
a:visited {
    color: purple;
}

a:hover {
    color: orange;
}

In this example, the link will appear purple if it has been visited, and when hovered, it will turn orange regardless of its visited state. The :visited pseudo-class is an important tool in designing intuitive navigation, helping users recognize their browsing history while maintaining user privacy.

It’s also worth noting that the order of pseudo-classes in CSS matters. To ensure proper behavior, the recommended sequence is: :link, :visited, :hover, and :active - often remembered by the mnemonic LVHA.

Syntax

:visited {
  /* ... */
}

Example

<body>

<h2>Check your Link Styles</h2>
<p>
<a href="https://www.google.com" class="custom-link">Visit Google</a>
</p>
<p>
<a href="#test-section" class="custom-link">Internal Test Link</a>
</p>

</body>
/* The default state of the link */
.custom-link:link {
color: #007BFF;
text-decoration: underline;
font-weight: bold;
}

/* The state after you have clicked/visited the URL */
.custom-link:visited {
color: #6c757d; /* Changes to a muted grey */
text-decoration: none; /* Removes underline */
}

/* Adding a hover effect for better UX */
.custom-link:hover {
color: #0056b3;
text-decoration: wavy underline;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS :visited pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS pseudo class.

This pseudo class is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee