On this page10 sections
  1. Learning Objectives
  2. 1. The Four States
  3. 2. Underlines
  4. 3. Background Colour on Hover
  5. 4. Link Buttons
  6. 5. The Cursor
  7. Common Beginner Mistakes
  8. Practice Questions
  9. Practice Answers
  10. Key Takeaways

Lecture 012: Styling Links

Category3: Text, Fonts & Content
Lecture012 of 057
Estimated video length10 min
TargetCSS3 · any modern browser
LevelBeginner

Links need to look clickable, show when they're hovered, and stay readable. CSS styles each state of a link separately, and can turn a plain link into a button.


Learning Objectives

  • Style the four link states: :link, :visited, :hover, :active
  • Control underlines with text-decoration
  • Turn links into buttons
  • Keep links accessible

1. The Four States

Example: hover over and click the link:

html
<style>
  a:link    { color: #1971c2; }   /* not visited */
  a:visited { color: #7048e8; }   /* visited */
  a:hover   { color: #e8590c; }   /* mouse over */
  a:active  { color: #c92a2a; }   /* being clicked */
</style>

<p>Read the <a href="https://example.com" target="_blank" rel="noopener">getting-started guide</a>.</p>

Write them in this order, or later rules hide earlier ones. A memory trick: LoVe HAte.


2. Underlines

Example

html
<style>
  .none  a { text-decoration: none; }
  .none  a:hover { text-decoration: underline; }
  .fancy a { text-decoration: underline; text-decoration-color: #ffa94d; text-decoration-thickness: 3px; text-underline-offset: 4px; }
</style>

<p class="none">Underline only on hover: <a href="#">Pricing</a></p>
<p class="fancy">A thick orange underline: <a href="#">Our story</a></p>

3. Background Colour on Hover

Example

html
<style>
  .menu a { padding: 6px 10px; color: #343a40; text-decoration: none; border-radius: 6px; }
  .menu a:hover { background: #fff3bf; }
</style>

<p class="menu"><a href="#">Home</a> <a href="#">Courses</a> <a href="#">Contact</a></p>

Example

html
<style>
  a.btn {
    display: inline-block;
    padding: 10px 20px;
    background: #2f9e44;
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: background 0.2s;
  }
  a.btn:hover  { background: #2b8a3e; }
  a.btn:active { transform: translateY(1px); }
  a.btn.outline { background: transparent; color: #2f9e44; border: 2px solid #2f9e44; }
  a.btn.outline:hover { background: #ebfbee; }
</style>

<a class="btn" href="#">Start learning</a>
<a class="btn outline" href="#">See courses</a>

display: inline-block lets the padding work properly on the inline <a>.


5. The Cursor

Links show a pointing hand automatically. Other clickable things can use it too:

css
.clickable { cursor: pointer; }

Other cursor values include default, text, move, not-allowed, wait and help.


Common Beginner Mistakes

1. Wrong state order. :hover before :visited never shows on visited links.

2. Removing underlines with no other clue. Links inside paragraphs must stand out by more than colour alone.

3. Links that look like buttons but act as buttons. If it performs an action rather than going somewhere, use <button>.


Practice Questions

  1. Name the four link states in the correct order.
  2. Remove the underline from links, but show it on hover.
  3. Which property sets the colour of an underline?
  4. Why add display: inline-block to a link button?
  5. Which cursor value shows a pointing hand?

Practice Answers

  1. :link, :visited, :hover, :active.
  2. a { text-decoration: none; } a:hover { text-decoration: underline; }
  3. text-decoration-color
  4. So the padding and size work like a box, not just around the text line.
  5. cursor: pointer;

Key Takeaways

  • Style :link, :visited, :hover, :active, in that order.
  • text-decoration controls underlines (colour, thickness, offset).
  • display: inline-block + padding + background makes link buttons.
  • Keep links clearly recognisable.