CSS Links
Links are how people move through your pages. In CSS you style the a element and its states — unvisited, visited, hovered, and active — so a link looks clickable, changes on interaction, and stays readable.
Link states at a glance
📊 Link states toolkit
| State | When it applies |
|---|---|
a / a:link |
Default / unvisited link |
a:visited |
Link the visitor has already opened |
a:hover |
Pointer is over the link |
a:active |
Link is being pressed (mousedown) |
text-decoration |
Underline on or off — a common link control |
Browsers often remember a helpful order nicknamed LVHA: :link, :visited, :hover, :active. Writing rules in that order keeps later states from being accidentally overridden.
Style the base link
Start with color and whether you want an underline. Many modern designs remove the default underline, then bring it back on hover.
Base link styles
cssa {
color: #0b5fff;
text-decoration: none;
}
Visited links
:visited can shift color slightly so returning visitors notice familiar paths. Keep the change subtle — privacy limits what you can style on visited links.
Visited tone
cssa:visited {
color: #5b4b8a;
}
Hover feedback
:hover is your clearest everyday signal. A color shift, underline, or both tells people “this is interactive” without shouting.
Hover underline
cssa:hover {
color: #0842b8;
text-decoration: underline;
}
Active — the press moment
:active fires while the link is pressed. A slightly darker tone gives a tiny “click” feeling.
Active press
cssa:active {
color: #062e80;
}
A calm nav-link habit
Group the LVHA states, keep hover obvious, and do not wipe focus outlines just to look flat. Keyboard users need a visible focus cue.
Quiet nav links
cssnav a:link,
nav a:visited {
color: #1a1a1a;
text-decoration: none;
}
nav a:hover,
nav a:active {
color: #0b5fff;
text-decoration: underline;
}
nav a:focus-visible {
outline: 2px solid #0b5fff;
outline-offset: 2px;
}
Try it yourself
- Set a base
acolor andtext-decoration: none. - Add
a:visitedwith a slightly different color. - On
a:hover, underline and darken the color. - Darken a bit more on
a:active. - Style
nav awith LVHA order and keep a:focus-visibleoutline.
Common mistakes
- Writing
:hoverbefore:link/:visitedso some states never win - Removing underline and any other clue that the text is a link
- Neon rainbow hovers on every word in a paragraph
outline: noneon links with no replacement focus style- Mixing this lesson with text-shadow / ellipsis effects (previous session)
Summary
- Style links with
aand the states:link,:visited,:hover,:active - LVHA order helps cascade behave as you expect
- Color +
text-decorationare the everyday controls - Hover should feel clear; visited changes stay subtle
- Keep a visible focus style for keyboard navigation
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top