Sub topic 5
Designing links that stand out from text
This chapter assumes you know basic HTML, CSS selectors, colors and pseudo-classes, and how to inspect an element in your browser's developer tools. It covers how to style links so readers can tell them apart from the text around them. Buttons, hover states and focus rings get their own chapters, so they appear here only briefly.
What a link needs to signal
A link sits inside running text, so it has to be recognizable without any help from its position or shape. Readers scan for links, and they decide whether to click based on what they see. If a link looks like plain text, many readers will not find it.
Three cues do most of the work:
- An underline, which is the oldest and most widely understood signal.
- A color that differs from the body text.
- A different state after the link has been visited.
Color alone is not enough. About 1 in 12 men has some form of color vision deficiency, and a color change may be invisible to them. An underline works for everyone, so keep it.
A baseline link style
This stylesheet gives every link an underline, a readable color, and a separate color for visited links.
a {
color: #1d4ed8;
text-decoration: underline;
text-decoration-thickness: 1px;
text-underline-offset: 0.15em;
}
a:visited {
color: #6d28d9;
}
a:hover {
color: #1e3a8a;
text-decoration-thickness: 2px;
}
a:focus-visible {
outline: 3px solid currentColor;
outline-offset: 2px;
}Each property has a job:
text-decoration: underlinekeeps the underline that browsers draw by default. Many resets remove it, so state it explicitly.text-decoration-thicknesssets the line weight. A thin line at rest and a thicker one on hover gives clear feedback without shifting the layout.text-underline-offsetmoves the line away from the letters so it does not cut through descenders such as g, p and y.a:visiteduses a purple that is clearly different from the blue, which helps readers see where they have already been.a:focus-visibledraws an outline for keyboard users. The next chapters cover focus in depth.
Order matters
The link pseudo-classes have equal specificity, so the one written last wins when several apply. If a:hover comes before a:visited, a visited link will ignore the hover color. A common memory aid is LVHFA: :link, :visited, :hover, :focus, :active.
Contrast against text and background
A link has two contrast relationships. The first is link color against the background. WCAG asks for a ratio of at least 4.5:1 for normal-size text. The second is link color against the surrounding body text, when the underline is removed. In that case WCAG asks for at least 3:1 between the two colors, plus another cue such as an underline on hover and focus. Keeping the underline always removes the second requirement entirely, which is why it is the safer choice.
Check ratios with the contrast checker in your browser's developer tools. In most browsers, inspecting a text element shows the ratio next to the color swatch.
Inline links versus standalone links
Inline links appear inside a sentence and need the full set of cues, because the text around them is the thing they must stand out from.
Standalone links appear in navigation bars, footers and card lists. Their position already says "this is a link", so you can drop the underline there. Do this only for links in a recognizable group, and add a clear hover and focus style.
.nav a {
text-decoration: none;
font-weight: 600;
}
.nav a:hover,
.nav a[aria-current="page"] {
text-decoration: underline;
}Common errors
- Removing the underline site-wide with
text-decoration: noneand relying on color alone. - Styling visited links the same as unvisited ones, which hides reading history.
- Making link text and body text nearly the same shade, such as a dark blue on near-black text.
- Styling non-links to look like links, such as blue underlined text that does nothing. Readers click it and lose trust.
- Using vague text like "click here". The label is covered in a later chapter.
Exercise
Your design team wants body links to be blue with no underline, and the blue is only slightly different from the dark gray body text. Name two problems with this and one change that fixes both.
Show answer
First, readers with color vision deficiency may not see any difference between links and text. Second, the color difference against the body text is probably under the 3:1 ratio WCAG asks for when no underline is present. Restoring text-decoration: underline fixes both, because the underline signals a link without depending on color.