CSS :visited Pseudo Class

The :visited selector selects and styles visited links in the page.

The :visited pseudo-class applies when the link has been visited by the user.

The styles that are modified using this selector are very limited. Browsers allow the following styles:

Version

CSS1

Syntax

:visited {
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      a{
      display:block;
      padding:5px;
      }
      a:visited {
      color: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>:visited selector example</h2>
    <a href="https://www.w3docs.com">W3docs</a>
    <a href="https://stackdev.io/">Stackdev</a>
  </body>
</html>

In the given example the :visited selector gives a green color to the visited link.

Another example where the unvisited, visited, hover, and active links are selected and styled:

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p { 
      font-size: 20px; 
      }
      /* unvisited link */
      a:link {
      color: #cccccc;
      }
      /* visited link */
      a:visited {
      color: #1c87c9;
      }
      /* mouse over link */
      a:hover {
      color: #8ebf42;
      }
      /* selected link */
      a:active {
      color: #666666;
      }
    </style>
  </head>
  <body>
    <h2>:visited selector example</h2>
    <p>Visit our 
      <a href="https://www.w3docs.com/">website</a>.
    </p>
  </body>
</html>

Practice Your Knowledge

Some styles that are modified using :visited pseudo class are




Related articles