agyanadda@gmail.com

CSS Links

Styling Content 1 min read Updated Dec 1, 2026 Topic 26 of 39

Links have four states you can style:

Selector When
a:link normal, not visited
a:visited already visited
a:hover mouse is over it
a:active being clicked

Write them in this order: LoVe HAte — link, visited, hover, active.

Remove underline

a { text-decoration: none; } — but keep links clearly different from normal text (colour, weight or underline on hover).

Example

Example — Link states and button links HTML
<style>
  a { color: #1f6feb; text-decoration: none; }
  a:hover { text-decoration: underline; }
  a:active { color: crimson; }
  .btn { display: inline-block; background: #1f386b; color: white; padding: 10px 18px; border-radius: 6px; }
  .btn:hover { background: #2d4f94; text-decoration: none; }
</style>

<p><a href="#">Hover over this link</a></p>
<a class="btn" href="#">Button-style link</a>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which selector styles a link when the mouse is over it?

Exercise 2 True / False

a:hover must come after a:link and a:visited to work properly.

Exercise 3 Fill in the Blank

text-decoration: ___; removes the underline.

Frequently Asked Questions

For privacy, browsers only allow colour changes in :visited.