The Wayback Machine - https://web.archive.org/web/20250122202633/https://www.geeksforgeeks.org/css-visited-selector/
Open In App

CSS :visited Selector

Last Updated : 30 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The :visited selector in CSS is used to select the visited links. For example, visit some link on the website and again see it, then it will find the changed color of that link. This color change is done by :visited the selector. 
The allowed CSS property of : visited selectors are listed below: 

  • color
  • border-color
  • background-color
  • outline color
  • column-rule-color
  • fill-color and stroke

Syntax:  

:visited {
// CSS Properties
}

Example: In this example, The :visited selector is used to style visited links, applying green color to the visited link in this example.

HTML
<!-- HTML code to illustrate :visited selectors -->
<!DOCTYPE html>
<html>

<head>
    <title>:visited selector</title>
    <style>
        /* visited CSS property */
        a:visited {
            color: green;
        }
    </style>
</head>

<body style="text-align:center">
    <h1>
        :visited Selector
    </h1>
    <h3>
        Click on the link
    </h3>

    <p>
        Visit Geeks:
        <a href="https://www.geeksforgeeks.org/" 
           target="_blank">
            geeksforgeeks.org
        </a>
    </p>

</body>

</html>

Output: 

Supported Browser:

  • Google Chrome 1
  • Microsoft Edge 12
  • Firefox 1
  • Opera 3.5
  • Safari 1

CSS :visited Selector – FAQs

What is the :visited selector in CSS?

The :visited selector applies styles to links that have already been visited by the user.

How does the :visited selector work with hyperlinks?

The :visited selector targets anchor elements (<a>) whose href attribute matches a URL the user has previously clicked on.

Can I change the color of visited links using the :visited selector?

Yes, you can change the color, but only certain CSS properties are allowed for :visited links due to privacy concerns.

What CSS properties can be used with the :visited selector?

Only color-related properties like color, and text-related properties such as text-decoration can be styled with :visited.

Why are there limitations on styling :visited links?

Browser limitations are in place to prevent privacy breaches, as extensive styling could reveal a user’s browsing history.


Similar Reads

three90RightbarBannerImg