Sub topic 12
Accessibility: WCAG text spacing
This chapter assumes you can write basic CSS and that you have read the earlier chapters on setting leading with unitless line-height and the measure with max-width in ch. Here you will learn what the Web Content Accessibility Guidelines (WCAG) require about text spacing. You will also learn how to test a page against those requirements and which layout habits break the test.
What the requirement says
WCAG is the W3C standard for accessible web content. Success criterion 1.4.12, Text Spacing, was added in WCAG 2.1 at conformance level AA. Many legal and procurement standards cite level AA.
The criterion does not tell you to use particular spacing. It says that if a user sets the four values below, the page must keep working. No content may be lost and no functionality may break.
| Property | Value the user may apply |
|---|---|
| Line height (leading) | At least 1.5 times the font size |
| Spacing after paragraphs | At least 2 times the font size |
| Letter spacing (tracking) | At least 0.12 times the font size |
| Word spacing | At least 0.16 times the font size |
Three points follow from this wording.
- The values are tested sizes, not design targets. Your design can use different spacing as long as it survives these values.
- The values are multiples of the font size. In CSS,
emunits express them directly. - Applying all four at once is the intended test. Letter and word spacing widen lines, and larger leading and paragraph spacing make blocks taller. Together they push text into new places.
The criterion has an exception for languages and scripts that do not use one of these properties. For example, some scripts do not use word spacing in the same way.
Why people change spacing
Some readers need more space. People with dyslexia, low vision, or certain cognitive disabilities often find that looser spacing reduces crowding between letters and helps the eye find the next line. Browser extensions, user stylesheets, and reading modes let them apply their own values. Your page has to tolerate that.
This links back to the earlier chapters. A sensible design already uses a unitless line-height of about 1.5 for body text, so the 1.5 requirement is usually met by default. The harder cases are the other three values and the components around the body text.
How it relates to other criteria
Several other WCAG criteria touch the same ideas. Do not confuse them.
- 1.4.8 Visual Presentation (AAA) asks authors to provide a mechanism for users to choose these settings. It also states that line width should be no more than 80 characters (40 for Chinese, Japanese, and Korean text), and that line spacing within paragraphs should be at least 1.5. It also asks that paragraph spacing be at least 1.5 times larger than the line spacing. This is the closest WCAG comes to the measure guidance from earlier chapters, and it is the stricter, optional level.
- 1.4.4 Resize Text (AA) requires that text can be enlarged to 200% without loss of content.
- 1.4.10 Reflow (AA) requires that content fits a 320 CSS pixel wide viewport without two-dimensional scrolling, apart from exceptions such as data tables.
Text spacing combines with these. A user may enlarge text and widen its spacing at once, so test the combination.
Testing with the override stylesheet
You can check your page by applying the four values with !important. The declaration overrides your own rules, which is how a user stylesheet or extension behaves.
p {
line-height: 1.5 !important;
letter-spacing: 0.12em !important;
word-spacing: 0.16em !important;
}
p + p {
margin-top: 2em !important;
}Paste this into the browser's developer tools as an extra stylesheet, or add it temporarily to the page. Then look for the failures listed later in this chapter.
What the rules do
line-height: 1.5 !importantis unitless, so each element multiplies it by its own font size.letter-spacing: 0.12emandword-spacing: 0.16emuseem, so they scale with the element's font size.p + p { margin-top: 2em }sets the gap between consecutive paragraphs to two font sizes. Margins between adjacent block siblings collapse, so the larger of the two margins wins. If your normal bottom margin is1.5remand the test top margin is2emat a 1rem font size, the gap becomes 2rem, not 3.5rem.
Limits of this snippet
The snippet only targets paragraphs. Real pages also have lists, table cells, headings, buttons, form labels, tooltips, and navigation. To widen the test, extend the selector list to those elements, for example p, li, td, th, label, button, a, h1, h2, h3. A universal selector (*) also works for the three inherited-style properties, but it touches every element and can make the page harder to inspect. Pick the approach that matches how thorough you need to be.
A dedicated bookmarklet or browser extension that applies the exact WCAG values is more convenient than editing CSS by hand. Use one if your team tests often. The result is the same.
Common failures and fixes
The failures below follow one pattern. A component was sized for the default spacing, and the new spacing no longer fits.
Fixed heights with hidden overflow
A card with a set height and overflow: hidden will cut off text once the leading and the word spacing push the text onto more lines.
/* Fails: the text no longer fits and is cut off */
.card {
height: 4.5rem;
overflow: hidden;
line-height: 1.2;
}
/* Passes: the card grows with its content */
.card {
min-height: 4.5rem;
padding: 0.5rem 1rem;
}Use min-height when you want a minimum size, and let the content set the rest.
Fixed line-height in pixels
A rule like line-height: 18px on a container is inherited by children as an absolute value, so a larger child font size ends up with cramped lines. Unitless values avoid this because each element calculates its own. The user's override then works as intended, because the !important value replaces your value anyway.
Buttons, tabs, and badges
Labels in small components often have fixed widths, white-space: nowrap, or a fixed height. Wider letter and word spacing makes the label overflow its border or collide with an icon. Prefer padding around the text to fixed dimensions, and allow wrapping where the layout can take it.
Absolute positioning
Text positioned over an image or inside an absolutely positioned box is placed relative to a size you guessed. Taller text may then overlap its neighbors. Keep text in the normal flow where you can.
Truncated text
Truncation with text-overflow: ellipsis is allowed only if the full content is still reachable. If the truncated text is the only copy, the content has been lost. Provide a way to read the whole string, such as wrapping, expansion, or an accessible alternative.
Clamped line counts
-webkit-line-clamp hides lines beyond a set number. Wider spacing produces more lines, so more text gets hidden. Treat clamped text like any other truncation.
What the criterion does not ask
Do not make all text roomy just to pass. The criterion asks that the layout survive user changes. It does not require your default design to use 0.12em letter spacing, and that value would look loose in body text. The earlier chapters still apply. A good default is a measure near 65 characters and a unitless leading around 1.5. Then confirm that the layout holds when a reader goes wider.
The reverse also matters. Users may sometimes choose spacing larger than the test values. Good flexible layouts with min-height, wrapping, and in-flow text handle that case as well.
Putting it together
A practical review has five steps.
- Build the page with sensible defaults: a unitless
line-heightnear 1.5 and amax-widthof about 65ch on text blocks. - Apply the override stylesheet, widened to the elements your page contains.
- Scan every template and component state: menus open and closed, error messages, and long translated strings, which are often longer than English.
- Fix each problem by removing fixed heights, setting
min-height, allowing wrapping, and moving text back into the normal flow. - Repeat the test at 200% zoom and at a 320px viewport to check the related resize and reflow criteria.
Write down which pages and components you tested. That record is useful evidence in an accessibility audit.
Exercise
A card has height: 5rem; overflow: hidden; line-height: 1.3; and a two-line title. After you apply the WCAG 1.4.12 overrides, the second line of the title is cut off. Name two changes that fix it, and explain why the override is not at fault.
Show answer
Replace height: 5rem with min-height: 5rem so the card can grow, and remove overflow: hidden (or at least stop it from hiding the text). You could also switch to padding instead of a fixed height. The override is not at fault because 1.4.12 only simulates the spacing a user may legitimately apply. The card failed because its fixed height assumed the default spacing, and the larger leading and wider letter and word spacing need more room.
Exercise
Your normal paragraph style is margin-block: 0 1.5rem with a 1rem font size. In the test, p + p { margin-top: 2em !important; } is applied. How large is the gap between two paragraphs, and why?
Show answer
The gap is 2rem. The bottom margin of the first paragraph (1.5rem) and the top margin of the second (2em, which is 2rem at a 1rem font size) collapse, and the larger of the two is used. The margins do not add up to 3.5rem.