Sub topic 5
Designing links that stand out from text
This chapter covers how to style links so readers can tell them apart from the text around them. It assumes you know basic HTML elements and attributes, and CSS selectors, the box model, colors and pseudo-classes. It also assumes you can inspect elements in your browser's developer tools.
What makes a link recognizable
A link is a control that navigates somewhere else. Earlier chapters covered affordances and signifiers: an affordance is what an element lets you do, and a signifier is the visible hint that tells you so. For links in running text, the signifier is almost always a combination of color and underline.
Browsers already supply this. The default style is blue text with an underline, and a purple color after you visit the link. Many designs remove the underline and keep only a color change. That choice is where most problems start.
Links come in two kinds, and they need different treatment:
- Inline links sit inside a sentence or paragraph. They compete with the surrounding text, so they need strong cues.
- Standalone links sit on their own, such as in navigation bars, footers, card lists, or a "Read more" line. Their position and grouping already tell the reader they are clickable, so they can use lighter cues.
Inline links: keep the underline
The underline is the strongest cue for an inline link. Readers have learned it over decades of web use. Color alone is weaker because some people cannot distinguish the colors involved, and because a colored word in a paragraph can look like emphasis.
WCAG (the Web Content Accessibility Guidelines) addresses this in success criterion 1.4.1, Use of Color. If a link in a block of text is distinguished from the text only by color, the link color must have at least a 3:1 contrast ratio against the surrounding text color. It must also show another cue, such as an underline, when the link receives hover or keyboard focus. Meeting this with color alone is hard. Keeping the underline is simpler and safer.
Here is a complete stylesheet for inline 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 non-color cue.text-decoration-thicknesscontrols the line weight. A thin line at rest and a thicker line on hover gives feedback without shifting the layout.text-underline-offsetmoves the line away from the text. This stops the underline from cutting through descenders, the parts of letters like g, p and y that drop below the baseline.:visiteduses a different hue so readers can see where they have been.:focus-visibledraws an outline when a keyboard user lands on the link. UsingcurrentColormakes the outline match the text color of the link state.
A usage example in HTML
<p>
Read the <a href="/docs/getting-started">getting started guide</a>
before you continue.
</p>With the stylesheet above, "getting started guide" appears in blue with a thin underline. After the reader visits the page, it turns purple. On hover, the underline thickens.
Contrast: the numbers
Link text must meet the normal text contrast requirement, which is 4.5:1 against its background for body-size text under WCAG level AA. The color #1d4ed8 on white gives a ratio well above that. You should still measure instead of guessing.
There is a second requirement when you rely on color. The link color must also differ from the neighboring body text by 3:1 if there is no underline. Dark gray body text such as #374151 and a mid blue rarely reach 3:1 against each other, which is why dropping the underline fails so often.
| Situation | Requirement | Practical answer |
|---|---|---|
| Link text against its background | 4.5:1 for normal text | Pick a dark enough blue and measure it |
| Link color against body text, no underline | 3:1, plus a second cue on hover and focus | Keep the underline instead |
| Focus outline against adjacent colors | 3:1 | Use a thick outline in a strong color |
| Visited color against its background | 4.5:1 | Check the purple as well as the blue |
The last row catches people out. The visited color is also link text, so it needs its own contrast check.
Standalone links
Links in navigation menus, footers and lists do not need an underline at rest. The surrounding layout communicates that they are links: they sit in a row or column of similar items, and they are in a region everyone expects to be clickable. A common pattern is to remove the underline at rest and add it on hover and focus:
.nav a {
color: #111827;
text-decoration: none;
padding: 0.5rem 0.75rem;
}
.nav a:hover,
.nav a:focus-visible {
text-decoration: underline;
text-decoration-thickness: 2px;
text-underline-offset: 0.2em;
}
.nav a[aria-current="page"] {
font-weight: 700;
text-decoration: underline;
}Notice the aria-current="page" rule. It marks the link for the page the reader is on. Marking the current page both visually and in the markup helps screen reader users as well.
Apply the no-underline pattern only where the context carries the meaning. If a link sits alone in the middle of a paragraph, treat it as an inline link.
External links and special destinations
Some links lead somewhere unexpected: another site, a file download, or a new tab. Readers benefit from a cue, but a cue must not replace clear link text.
- Put the information in the text where you can: "Annual report (PDF, 2 MB)".
- If you add an icon, include a text alternative or hide the decorative icon from assistive technology.
- Avoid
target="_blank"unless you have a reason. If you use it, addrel="noopener"for older browsers and say in the link text that it opens a new tab.
<a href="https://example.com/report.pdf" download>
Annual report (PDF, 2 MB)
</a>
<a href="https://example.org" target="_blank" rel="noopener">
Example Org (opens in a new tab)
</a>Common errors
These are the problems you will meet most often when reviewing link styles.
- Removing the underline with
text-decoration: noneon all anchors. This leaves color as the only cue inside paragraphs. Scope the removal to navigation components instead of the globalaselector. - Giving bold or colored non-link text the same look as links. If a heading accent or a highlighted term uses the link color, readers click it and nothing happens. Reserve the link color for links.
- Removing the focus outline. Writing
a:focus { outline: none; }without a replacement makes keyboard navigation unusable. Style:focus-visibleinstead of deleting the outline. - Using the same color for
:visitedand unvisited links. Readers lose the history cue. Browsers also restrict what:visitedcan change, for privacy reasons. You can change color-related properties, but not layout properties likepaddingorfont-size. - Putting
href="#"on something that is really a button. A link that does not navigate is a button. The next chapters on interaction states and labels build on this. - Underlining text that is not a link. Underlines on plain text make readers click and fail. Use italics or bold for emphasis.
- Link text that says "click here". Screen reader users often list all links on a page out of context, so each label must make sense alone.
Order of link states in CSS
The pseudo-classes for links have a specificity tie, so source order decides which rule wins. The traditional order is :link, :visited, :hover, :active, remembered as LVHA. If you place :hover before :visited, a visited link will ignore the hover color, because the :visited rule comes later and wins.
a:link { color: #1d4ed8; }
a:visited { color: #6d28d9; }
a:hover { color: #1e3a8a; }
a:active { color: #172554; }If you use :focus-visible as well, put it after these so its outline appears in every state.
How a reader decides a word is a link
The diagram below shows the order of cues a reader typically uses when scanning a paragraph.
The path through "No underline" costs the reader effort. Some readers, such as those with color vision deficiency, will not see the color difference at all.
A quick checklist for a link style
- Inline links have an underline at rest.
- Link color has 4.5:1 contrast against the background.
- Visited color also passes 4.5:1 and differs from the unvisited color.
- Hover changes something beyond color, such as underline thickness.
- Keyboard focus shows a visible outline with 3:1 contrast.
- Navigation links without underlines are grouped so their purpose is clear.
- Link text makes sense when read alone.
Exercises
Exercise
A designer wants links inside article paragraphs to be dark blue with no underline, and says the blue is different enough from the gray body text. Which two WCAG requirements must be met for this to pass, and what is the simpler fix?
Show answer
The link color must have at least 3:1 contrast against the surrounding body text, and the link must show an additional cue (such as an underline) on hover and keyboard focus. The simpler fix is to keep the underline at rest, which meets the non-color cue requirement directly.
Exercise
Your stylesheet lists a:hover before a:visited. A user hovers over a link they have already visited and sees no hover color change. Why, and how do you fix it?
Show answer
Both rules have equal specificity, so the later rule wins. a:visited comes after a:hover and overrides its color for visited links. Reorder the rules as link, visited, hover, active (LVHA), so hover comes after visited.
Exercise
Write CSS so that links inside a .nav element have no underline at rest, but show a 2px underline on hover and on keyboard focus.
Show answer
.nav a { text-decoration: none; } .nav a:hover, .nav a:focus-visible { text-decoration: underline; text-decoration-thickness: 2px; }