Sub topic 12
Accessible spacing, touch targets and text-spacing overrides
This chapter assumes you know the box model, rem and em units, custom properties, and the spacing scale, gap and flow rule from earlier chapters. Spacing does more than make a page look tidy. It also decides whether people can hit a control, read a paragraph, and see your groupings when their settings differ from yours.
Why spacing is an accessibility issue
Three groups of users depend on your spacing choices:
- People using touch screens, a tremor-affected mouse hand, or a stylus need targets that are large enough and far enough apart to hit without error.
- People with dyslexia, low vision or cognitive disabilities often override line height, letter spacing and word spacing with a browser extension or user stylesheet.
- People who zoom or enlarge the default font size need layouts that reflow instead of overlapping.
Your grouping system must survive all three. A layout where groups are visible only because of exact pixel gaps, fixed-height boxes and clipped text will break.
Touch targets: size and spacing
A touch target is the area of the screen that responds to a tap or click. WCAG (the Web Content Accessibility Guidelines) has two success criteria about it:
| Criterion | Level | Requirement |
|---|---|---|
| 2.5.8 Target Size (Minimum), WCAG 2.2 | AA | Targets are at least 24 by 24 CSS pixels, or have enough spacing around them |
| 2.5.5 Target Size (Enhanced), WCAG 2.1 | AAA | Targets are at least 44 by 44 CSS pixels |
The 24 pixel criterion has a spacing exception. A smaller target passes if a 24 pixel circle centered on it does not overlap another target or that target's circle. White space can therefore make up for a small control. Apple's guidelines suggest 44 points and Material Design suggests 48 density-independent pixels, so 44 to 48 pixels is a good practical goal for primary controls.
Padding makes the target, gap separates targets
Use padding to enlarge the clickable area, because padding is part of the element's own box and responds to taps. Margin is outside the box and does not. Use gap or margin to keep neighboring targets apart.
.icon-button {
min-inline-size: 2.75rem;
min-block-size: 2.75rem;
padding: var(--space-2);
display: inline-grid;
place-items: center;
}
.toolbar {
display: flex;
gap: var(--space-2);
}The 2.75rem value equals 44 pixels at the default 16 pixel font size and scales with the user's font setting. Using min- properties lets the button grow if its content does.
Inline links in text
Links inside a sentence are exempt from the size requirement, because their size is set by the surrounding text. Lists of links are not exempt. Navigation lists, footer links and tag lists need real vertical room:
.link-list {
display: grid;
gap: var(--space-1);
padding: 0;
list-style: none;
}
.link-list a {
display: block;
padding-block: var(--space-2);
}Here the padding is on the a element, so the whole row is clickable. If you used margin between list items instead, the gaps would be dead zones, and users would tap between rows and get nothing.
Spacing and grouping work together
Large targets need space around them, which pushes the controls of one group away from the next. Keep the proximity ratios from earlier chapters: the gap between buttons within a group must still be smaller than the gap between groups. A toolbar with --space-2 between buttons and --space-5 between button groups meets both the touch requirement and the grouping requirement.
.toolbar-groups {
display: flex;
flex-wrap: wrap;
gap: var(--space-5);
}
.toolbar-groups > .toolbar {
gap: var(--space-2);
}Wrapping matters. With flex-wrap: wrap, groups drop to a new row on a narrow screen instead of shrinking the targets.
Text-spacing overrides (WCAG 1.4.12)
Success criterion 1.4.12 Text Spacing (Level AA) says that users must be able to set the following values without loss of content or functionality:
- Line height 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 those values yourself. You must make sure that when a user applies them, nothing is clipped, hidden or overlapped. Users apply them with extensions, bookmarklets or their own stylesheets, usually with !important, which beats your normal rules.
A test stylesheet
You can simulate an override in the browser's developer tools, or add a temporary stylesheet:
* {
line-height: 1.5 !important;
letter-spacing: 0.12em !important;
word-spacing: 0.16em !important;
}
p {
margin-bottom: 2em !important;
}Load your page with this applied and look for the failures below.
Common failures and fixes
| Symptom with overrides applied | Cause | Fix |
|---|---|---|
| Text is cut off at the bottom of a button or card | Fixed `height` | Use `min-block-size` and padding, not `height` |
| Text overlaps the next element | Absolute positioning or fixed-height container | Let the container size to its content |
| A heading no longer sits closer to its section | Override changed paragraph margins only, heading gaps stay fixed | Use relative units (`em`, `rem`) so spacing scales together |
| Text hidden in a truncated label | `overflow: hidden` with fixed width | Allow wrapping, or use `min-inline-size` |
| Groups look identical | Gaps are so small that the override's paragraph spacing exceeds them | Make group gaps clearly larger than paragraph spacing |
The last row is the grouping-specific risk. If a user forces margin-bottom: 2em on every paragraph, the space between paragraphs inside a card can become larger than the space between two cards. Your groups blur together. The defense is to give between-group spacing a wide margin over within-group spacing, and to avoid relying on small differences.
Write spacing that tolerates overrides
Prefer these habits:
- Size boxes with padding and
min-*sizes. Avoid fixedheighton anything that holds text. - Use
remoremfor spacing so it scales with the font size. - Use unitless
line-height, for example1.5, so it recalculates for each element's own font size. - Let flex and grid containers wrap, and let text wrap inside them.
- Do not use
overflow: hiddenon text containers unless you provide another way to read the content.
.card {
padding: var(--space-4);
min-block-size: 8rem;
line-height: 1.5;
}
.card-title {
margin: 0;
overflow-wrap: anywhere;
}overflow-wrap: anywhere allows a long word, such as a URL, to break instead of overflowing when letter spacing increases.
Zoom and font-size changes
Users who raise their browser's default font size or zoom to 200 percent also stress your spacing. Two points follow from this.
First, spacing in rem scales with the root font size, but spacing in px does not. If the text grows and the gaps stay fixed, groups tighten visually. Use rem for the spacing scale, as the earlier chapters did.
Second, WCAG 1.4.10 Reflow (Level AA) requires content to work at a width of 320 CSS pixels, equal to 400 percent zoom on a 1280 pixel window, without two-dimensional scrolling. Responsive spacing from the previous chapter helps here, but check that padding does not eat the content width. A card with padding: var(--space-6) on each side uses 8rem of a 20rem viewport. Lower the padding at narrow widths:
.card {
padding: clamp(var(--space-3), 4vw, var(--space-5));
}Focus indicators need room
Keyboard users see which control is active through a focus outline. The outline is drawn outside the border box by default, so spacing decides whether it is visible. If a parent has overflow: hidden and the child sits at its edge, the outline is clipped. Leave room with a small offset and padding on the container.
:focus-visible {
outline: 3px solid #1a4fd6;
outline-offset: 2px;
}
.scroll-area {
padding: var(--space-1);
}The WCAG 2.2 criterion 2.4.11 Focus Not Obscured (Minimum) also expects that a focused item is not fully hidden behind sticky headers. When you add a sticky header, set scroll-padding-block-start on the page so focused elements scroll to a visible position:
html {
scroll-padding-block-start: 5rem;
}Putting it together: a checklist
- Every standalone control is at least 24 by 24 CSS pixels, with 44 pixels as the goal for primary actions.
- Neighboring targets are separated by a gap, not by dead margins inside a list.
- With the test stylesheet applied, no text is clipped or overlapping.
- Between-group spacing still clearly exceeds within-group spacing under the overrides.
- At 200 percent zoom and 320 pixel width, there is no horizontal scrolling and padding does not crowd out content.
- Focus outlines are fully visible, including under sticky headers.
Summary
Accessible spacing means choosing the right property for each job. Padding builds the target, gap separates targets and groups, relative units let spacing follow the user's settings, and min-* sizing lets boxes grow when text does. Test with the 1.4.12 values, because that is where fixed heights and tight group gaps fail.
Exercise
A navigation list has li { margin-bottom: 0.5rem; } and each link inside is an inline a with no padding, about 18 pixels tall. Users on phones often tap the gap between links and nothing happens. Rewrite the CSS so that each link is at least 44 pixels tall, the whole row is clickable, and the rows are still separated.
Show answer
Move the spacing from the list items onto the links and use gap on the list. For example: ul { display: grid; gap: var(--space-1); padding: 0; list-style: none; } and li a { display: block; padding-block: 0.75rem; min-block-size: 2.75rem; }. The display: block and padding make the link fill the row, so the margin dead zones are gone. min-block-size: 2.75rem guarantees 44 pixels at the default font size, and the grid gap keeps a small visible separation.
Exercise
You apply the WCAG 1.4.12 test stylesheet to a page of product cards. Each card has height: 12rem; overflow: hidden;, and the last line of the description is cut off. Also, the space between paragraphs inside a card (2em after the override) is now larger than the gap of 1rem between cards. What two changes fix these problems?
Show answer
First, replace height: 12rem with min-block-size: 12rem and remove overflow: hidden, so the card grows with its text. Second, increase the gap between cards well above the paragraph spacing a user can force, for example gap: var(--space-5) (2.5rem) or larger, and keep padding inside the card, so the card boundaries and the grouping stay visible even when paragraph margins grow.