CSS Links
Style links with CSS to create engaging, accessible navigation. Learn link states, modern effects, and best practices for user experience.
How do you style links in CSS?
Style the a element and its states in LVHA order: :link, :visited, :hover, :active. Add a visible :focus-visible outline for keyboard users. To remove the underline, use text-decoration: none, but keep some other visual cue so links stay recognisable.
a {
color: #2563eb;
text-decoration-thickness: 1px;
text-underline-offset: 3px;
}
a:visited { color: #7c3aed; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }Link Styling Demo
Link Pseudo-classes
a:link { color: blue; }
a:visited { color: purple; }
a:hover { color: red; }
a:active { color: orange; }Different states of links for user interaction
Text Decoration
a { text-decoration: none; }
a { text-decoration: underline; }
a:hover { text-decoration: overline; }Control underlines and other text decorations
Link Buttons
.btn {
padding: 10px 20px;
background: #007bff;
color: white;
text-decoration: none;
}Style links to look like buttons for actions
Hover Effects
a:hover {
transform: scale(1.05);
transition: all 0.3s ease;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}Animated hover effects for better user experience
External Link Styling
a[href^="http"]::after {
content: " ↗";
font-size: 0.8em;
}Indicate external links with visual cues
Focus States
a:focus {
outline: 2px solid #007bff;
outline-offset: 2px;
border-radius: 2px;
}Accessible focus indicators for keyboard navigation
Code Editor
<p>Read the <a href="#">CSS Grid guide</a> or visit <a href="https://example.com" class="ext">an external site</a>.</p>
<a href="#" class="button-link">Button-style link</a>Preview
Your Learning Path
What You've Learned
- ▶Link states: link, visited, hover, active
- ▶Modern link effects and animations
- ▶Button-style and navigation links
What's Next
- ▶CSS Lists - List styling and customization
- ▶CSS Tables - Table styling and layout
Pro Link Tip
Always provide clear visual feedback for link states. Users should know when they're hovering over a clickable element and when they've visited a link before.
CSS Links — step by step
Link State Pseudo-classes
Style links by state: :link (unvisited), :visited, :hover, :focus, :active — always declare them in LVHFA order to avoid specificity conflicts.
🎯 Quick Check
Which link pseudo-class applies when a user is actively clicking the link?
Styling Links with CSS: summary
Key points
- For privacy reasons,
:visitedonly allows colour changes. - Links within body text should be distinguishable without relying on colour alone (WCAG).
- A button-styled link (
a.button) is fine for navigation; use a real<button>for actions.
Frequently asked questions
›How do I remove the underline from links?
Set text-decoration: none on a. In body text, keep another cue such as bold weight, a colour with enough contrast, or an underline on hover.
›Why should link states follow LVHA order?
The four selectors have the same specificity, so the last one wins. LVHA order ensures :hover and :active aren't overridden by :link or :visited.