CSS :link Pseudo Class

The :link pseudo-class is used to select and style unvisited links in a page. It applies to links that have not yet been visited.

An element can be both :visited and :active so as the :link pseudo-class will have an effect.

The :link pseudo-class matches every unvisited <a> , <area>, or <link> element that has a href attribute.

Version

CSS1

Syntax

:link {
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      a:link {
      background-color: #ccc;
      }
    </style>
  </head>
  <body>
    <h2>:link selector example</h2>
    <a href="https://www.w3docs.com">w3docs</a>
    <a href="https://stackdev.io/">Stackdev</a>
  </body>
</html>

Another example with the :link selector:

Example

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

In this example, mouse over the links and watch how they will be changed:

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      a{
      display:block;
      padding:5px 0 10px;
      font-weight:bold;
      }
      a.one:link { 
      color: #ccc;
      }
      a.one:visited { 
      color: #095484;
      }
      a.one:hover { 
      color: #8ebf42;
      }
      a.two:link {
      color: #ccc;
      }
      a.two:visited {
      color: #095484;
      }
      a.two:hover {
      font-size: 150%;
      }
      a.three:link {
      color: #ccc;
      }
      a.three:visited {
      color: #095484;
      }
      a.three:hover {
      background: #8ebf42;
      }
      a.four:link {
      color: #ccc;
      }
      a.four:visited {
      color: #095484;
      }
      a.four:hover {
      font-family: monospace;
      }
      a.five:link {
      color: #095484;
      text-decoration: none;
      }
      a.five:visited {
      color: #095484; text-decoration: none; 
      }
      a.five:hover {
      text-decoration: overline underline; 
      }
    </style>
  </head>
  <body>
    <h2>:link selector example</h2>
    <p>
      <a class="one" href="#">This link changes color</a>
      <a class="two" href="#">This link changes font-size</a>
      <a class="three" href="#">This link changes background-color</a>
      <a class="four" href="#">This link changes font-family</a>
      <a class="five" href="#">This link changes text-decoration</a>
    </p>
  </body>
</html>



Related articles