Using the :link and :visited Selectors

Description

The :link selector matches hyperlinks and the :visited selector matches visited hyperlinks.

  • :link
    Selects link elements.
    CSS Version 1
  • :visited
    Selects link elements that the user has visited.
    CSS Version 1

Only some properties can be applied to links using the :visited selector. You can change the colors and the font, but that's about it.

Example

The following code shows the :link and :visited selectors.


<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
:link {<!--from  w w w. ja va  2s.  c om-->
  border: thin black solid;
  background-color: lightgrey;
  padding: 4px;
  color: red;
}

:visited {
  background-color: grey;
  color: white;
}
</style>
</head>
<body>
  <a href="http://java2s.com">Visit the website</a>
  <p>
    I like <span>HTML</span>.
  </p>
  <a href="http://w3c.org">Visit the W3C website</a>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table