Skip to main content

Beginner-Friendly Topic

Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!

Lesson 6 of 10

CSS Links & Link Styling

Links are the most interactive elements in HTML. CSS lets you style links for different states - default, visited, hovered, focused, and active. Proper link styling improves usability and accessibility.

10 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Link States (LVFHA Order)

  • :link - Unvisited links. Default: blue with underline
  • :visited - Previously visited links. Default: purple. Limited styling for privacy
  • :focus - Keyboard focus (Tab key). Critical for accessibility - never remove without a replacement
  • :hover - Mouse hover state. Add color change, underline animation, or background
  • :active - Being clicked (mousedown). Brief visual feedback
  • Order matters - LVFHA: Link, Visited, Focus, Hover, Active. Wrong order = broken states
  • text-decoration: none - Removes default underline. Always provide another visual indicator for accessibility

Link Styling Code

Link Styling Code
/* Modern link styles */
a {
  color: #667eea;
  text-decoration: none;
  transition: color 0.2s ease;
}
a:hover { color: #E44D26; }
a:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Animated underline effect */
.link-animated {
  color: #333;
  text-decoration: none;
  position: relative;
}
.link-animated::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: #E44D26;
  transition: width 0.3s ease;
}
.link-animated:hover::after {
  width: 100%;
}

/* Button-style link */
.link-button {
  display: inline-block;
  background: #E44D26;
  color: white;
  padding: 10px 24px;
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.2s, transform 0.2s;
}
.link-button:hover {
  background: #c0392b;
  transform: translateY(-2px);
}

Tip

The animated underline effect (::after with width: 0 growing to 100% on hover) gives links a modern, interactive feel with zero JavaScript. Store it as a reusable class. It works for nav links, inline article links, and portfolio items.

Diagram
Loading diagramโ€ฆ

Always specify link pseudo-classes in LVHA order to prevent cascade override conflicts

Common Mistake

Writing a { outline: none } to remove all focus styles breaks keyboard accessibility. Keyboard users navigate with Tab and rely on focus rings to know where they are. Use a:focus-visible { outline: 2px solid currentColor } instead - it shows only during keyboard navigation.

Practice Task

Style links with the full LVFHA pattern: (1) unvisited โ†’ #667eea, (2) visited โ†’ #764ba2, (3) hover โ†’ color change + animated underline using ::after, (4) :focus-visible โ†’ 2px outline. Then press Tab in your browser to keyboard-navigate and verify the focus styles work.

Quick Quiz

Key Takeaways

  • Links are the most interactive elements in HTML.
  • :link - Unvisited links. Default: blue with underline
  • :visited - Previously visited links. Default: purple. Limited styling for privacy
  • :focus - Keyboard focus (Tab key). Critical for accessibility - never remove without a replacement

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done