Sub topic 8
Target size and spacing
This chapter assumes you can write basic HTML and CSS, including the box model and pseudo-elements, and that you can inspect an element's computed size in your browser's developer tools. It builds on the button styling from the previous chapters. A button can look clickable and still be hard to hit.
Why size matters
A target is any area that responds to a click or tap. Small targets cause missed taps and accidental taps on a neighbor. They affect people using touchscreens, people with hand tremors, and anyone using a mouse on a trackpad. A fingertip covers roughly 8 to 10 mm, much larger than a mouse pointer.
Size guidelines
| Source | Size | Notes |
|---|---|---|
| WCAG 2.2, 2.5.8 Target Size (Minimum), level AA | 24 by 24 CSS pixels | Smaller targets pass if enough space surrounds them |
| WCAG 2.2, 2.5.5 Target Size (Enhanced), level AAA | 44 by 44 CSS pixels | Stricter goal |
| Apple Human Interface Guidelines | 44 by 44 points | Touch targets on iOS |
| Material Design | 48 by 48 dp | Touch targets on Android |
Use 44px as the working default for buttons, as the button example in this tutorial does with min-height: 44px. Treat 24px as the floor, not the goal.
WCAG 2.5.8 has a spacing exception. A target smaller than 24px passes if a 24px circle centered on it does not overlap another target or that target's circle. It also exempts links inside a sentence or block of text, and controls whose size the browser sets and you have not changed.
Make the target big, not just the icon
An icon button is the usual offender. A 16px glyph is fine to look at, but the clickable box must be larger. Size the element, not the icon.
<button type="button" class="icon-btn" aria-label="Close dialog">×</button>.icon-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 44px;
min-height: 44px;
padding: 0;
border: 0;
background: transparent;
font-size: 1.5rem;
cursor: pointer;
}min-width and min-height set a floor. They let the button grow when the label is longer or the user enlarges the text. A fixed width and height would clip the content.
Space between targets
Large targets packed edge to edge still cause mistakes, because a slightly off tap lands on the wrong control. Leave a gap, and make it larger for actions with serious consequences, such as Delete next to Save.
.btn-row {
display: flex;
flex-wrap: wrap;
gap: 12px;
}gap is better than margins on each button. It adds space only between items, and it wraps cleanly on narrow screens when you add flex-wrap.
Enlarging the hit area without changing the look
Sometimes the design calls for a small visible element, such as a compact text link in a table row. You can extend the clickable area with a pseudo-element. The pseudo-element belongs to the link, so clicks on it activate the link.
.link-compact {
position: relative;
}
.link-compact::after {
content: "";
position: absolute;
inset: -10px;
}inset: -10px pushes the invisible box 10px beyond each edge. The extension only works if the area is free. If it overlaps a neighboring control, one of them loses clicks, and the one later in the page order wins. Check this in the developer tools by hovering the element and looking at the highlighted box.
Where the guidelines relax
Inline links within a paragraph are exempt from the 24px rule, because their size follows the text. You can still help readers:
- Use a comfortable body size, at least 16px.
- Set
line-heightto about 1.5, so links on adjacent lines do not nearly touch. - Avoid placing several links in a row with only a thin space between them. Use a list with spacing, or a
gap.
Common mistakes
- Sizing a visual icon at 16px and stopping there.
- Using
widthandheightinstead ofmin-widthandmin-height. - Placing two destructive or opposing buttons with no gap.
- Extending a hit area with a pseudo-element that covers the next control.
- Testing only with a mouse. A target that is easy to click may be hard to tap.
Exercise
A 20px by 20px icon button sits 4px away from a second 20px by 20px icon button. Does it meet WCAG 2.5.8 through the spacing exception, and what is a simple fix?
Show answer
No. A 24px circle centered on each button reaches beyond its 20px edge by 2px on every side, so with only 4px between the buttons the circles overlap the neighboring button, which the exception does not allow. The simplest fix is to set min-width: 44px; min-height: 44px on both buttons, keeping the icon small inside, and add gap: 12px between them.