CSS Links

Style links in their different states.

✍️ 3 exercises + code challenge in this lesson

Links have four states you can style, in this order:

  1. a:link: a normal, unvisited link.
  2. a:visited: a link the user has visited.
  3. a:hover: when the mouse is over it.
  4. a:active: the moment it is clicked.
Remember the order with "LoVe HAte": link, visited, hover, active.

Links can also be styled to look like buttons with padding, background and border-radius.

Key Takeaways: CSS Links

Mastering CSS Links helps you write clean and reliable CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

CSS Links Code Example

CSS
<style>
  a:link    { color: #2563EB; }
  a:visited { color: #7C3AED; }
  a:hover   { color: #E34F26; text-decoration: none; }
  a:active  { color: #14B8A6; }

  a.btn {
    display: inline-block; padding: 10px 20px; margin-top: 12px;
    background: #2563EB; color: white; border-radius: 8px; text-decoration: none;
  }
  a.btn:hover { background: #1D4ED8; }
</style>

<p><a href="#">A normal link</a></p>
<a class="btn" href="#">A link styled as a button</a>
Free sign-in required · Google login available

CSS Links Practice Exercises

Check what you learned in “CSS Links”.

/ 3 solved
Fill in the blank

Style links when the mouse is over them.

a: {
  color: red;
}
✓ Correct! Not quite. Try again.
Multiple choice

What is the correct order of link pseudo-classes?

✓ Correct! Not quite. Try again.
Code challenge

Remove the underline from the link.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services