Skip to content

CSS Tutorial CSS Links

CSS Link States

Lesson 57 of 182 2 min read By Deepak Paswan Updated Oct 4, 2026

A link is not always in the same condition. CSS lets you style each one.

Pseudo-classWhen it applies
a:linkA link that has not been visited
a:visitedA link the visitor has already opened
a:hoverThe mouse is over it
a:activeIt is being pressed right now
a:focusIt has keyboard focus
index.html
HTML
<style>
  a:link    { color: #1a5276; }
  a:visited { color: #6c3483; }
  a:hover   { color: #d94a00; text-decoration: none; }
  a:active  { color: #b00020; }
</style>
<p><a href="#one">An unvisited link</a></p>
<p><a href="">A link to this page, probably counts as visited</a></p>

The order matters: LVHA

Write the rules in this order: Link, Visited, Hover, Active. “LoVe HAte” is the traditional way to remember it.

Why? All four rules have the same strength, so if two apply at once, the later one wins. A visited link under the mouse matches both :visited and :hover. With :hover written after :visited, hover wins, which is what you want.

Privacy limits on :visited

For privacy, browsers only let you change colors in :visited. You cannot change its size, add a background image or run anything based on it, because that would let a page discover which sites a visitor has been to.

Don’t forget focus

Hover is for the mouse. Keyboard users need :focus or :focus-visible too. Style them together:

style.css
CSS
a:hover,
a:focus-visible {
  color: #d94a00;
}

More about focus in CSS Focus Styles.

warning
Hover before visited
If your hover color seems not to work on links you have already visited, the :visited rule is probably below it. Put them in LVHA order.