Sub topic 12
Accessibility: WCAG text spacing
This chapter covers the WCAG text spacing requirements and how they affect the measure and leading choices from earlier chapters. It assumes you can write basic HTML and CSS and know what leading and measure mean. WCAG is the Web Content Accessibility Guidelines, published by the W3C.
What the criterion requires
WCAG 2.1 success criterion 1.4.12 (Text Spacing) is a Level AA requirement. It does not tell you to use particular spacing values. It says that if a user overrides text spacing, nothing may be lost: no clipped text, no overlapping text, and no content that disappears.
Some readers need looser spacing. People with dyslexia or low vision often apply a custom stylesheet or a browser extension to widen it. If your layout only works with your own spacing values, their changes can break it.
The criterion names four values. A page must still work when a user sets all of them at once:
| Property | Minimum the page must tolerate |
|---|---|
| Line height (leading) | At least 1.5 times the font size |
| Spacing after paragraphs | At least 2 times the font size |
| Letter spacing | At least 0.12 times the font size |
| Word spacing | At least 0.16 times the font size |
You do not have to use these values as your design. Your page only has to survive them.
How this connects to your design
A line-height of 1.5 is already within the common range you chose earlier, so leading itself is rarely the problem. Letter and word spacing are different. They make every line longer, so text wraps earlier and the paragraph takes more vertical space.
This is where a ch-based max-width helps. Because ch is relative to the font, the measure scales with the text. A container whose height is fixed in pixels is the usual failure. When the text grows taller, it overflows and gets clipped or overlaps the next element.
Testing with the override values
To test your page, apply the values from the criterion with !important, so they beat your own rules. You can paste this into the browser's developer tools as a stylesheet, or load it through a user stylesheet extension.
p {
line-height: 1.5 !important;
letter-spacing: 0.12em !important;
word-spacing: 0.16em !important;
}
p + p {
margin-top: 2em !important;
}The last rule sets the gap between paragraphs to twice the font size. Then check the page by eye for these problems:
- Text cut off at the edge of a button, card, or navigation item.
- Lines that overlap the line below or an adjacent element.
- Text hidden behind a fixed header or inside a box with
overflow: hidden. - Horizontal scrolling that did not appear before.
Writing CSS that survives overrides
Most failures come from a few habits. Each has a simple fix.
- Use
min-heightinstead ofheighton containers that hold text. The box can then grow. - Avoid
overflow: hiddenon text containers unless you are sure the content cannot grow. - Keep line-height unitless, as in
line-height: 1.5. A fixed value such as24pxdoes not scale with the font size. - Size padding and widths in
rem,em, orchso they grow with the text. - Let text wrap. Avoid
white-space: nowrapon labels that could get longer.
.card {
min-height: 8rem;
padding: 1rem;
}
.card p {
max-width: 65ch;
line-height: 1.5;
}Common mistakes
- Testing only the paragraphs. Buttons, form labels, tabs, and table cells are more likely to clip.
- Forgetting
!important. Without it, your own selectors can win and the test proves nothing. - Treating the four values as a style guide. They are the most a page must tolerate, not the target.
Exercise
A card has height: 6rem and overflow: hidden. After you apply the WCAG text spacing override values, the last line of its text disappears. Which two CSS changes fix this, and why?
Show answer
Change height: 6rem to min-height: 6rem, and remove overflow: hidden (or change it to visible). With a fixed height and hidden overflow, taller text is clipped. With min-height, the card grows to fit the larger text, so no line is lost.
Exercise
Write the four CSS declarations, with their values, that you would apply to test a page against WCAG 1.4.12.
Show answer
line-height: 1.5, letter-spacing: 0.12em, word-spacing: 0.16em, and a paragraph gap of margin-top: 2em between paragraphs. Each should use !important so it overrides the page's own rules.