Sub topic 10
Designing for touch and pointer capability
This chapter assumes you can write min-width media queries, know the CSS box model, and can use browser developer tools. It covers two problems: making controls easy to hit with a finger, and styling hover only where hover exists.
Why screen width is not enough
A narrow screen is usually a touch screen, but not always. A tablet can be wide and touch-only. A small laptop window can be narrow and use a mouse. Width queries say nothing about how the user points at things, so you need a second set of checks that look at the input device.
Size touch targets in the base styles
Fingers are less precise than mouse cursors. A commonly cited guideline is a target of about 44 by 44 CSS pixels (WCAG 2.2 sets a 24px minimum, and 44px is the stricter level 2.5.5). Put the size in the base styles, so every device gets it, and don't add it later in a media query.
.button {
min-block-size: 2.75rem;
padding-inline: 1rem;
}2.75rem is 44px at the default font size. Using min-block-size lets the button grow with its text instead of clipping it. Also leave space between neighbouring targets, for example with gap, so a tap on one doesn't land on another.
Ask about the input device
Interaction media features describe the primary input device:
| Feature | Value | Meaning |
|---|---|---|
| `hover` | `hover` | The primary input can hover (mouse, trackpad). |
| `hover` | `none` | It cannot (most touch screens). |
| `pointer` | `fine` | Precise pointing (mouse, stylus). |
| `pointer` | `coarse` | Imprecise pointing (finger). |
Use them to apply hover styling only where hover works:
.button {
min-block-size: 2.75rem;
padding-inline: 1rem;
}
@media (hover: hover) and (pointer: fine) {
.button:hover {
background: #e8eefc;
}
}This keeps the mobile-first pattern. The base rule is correct for touch, and the query adds a refinement for capable devices. Without the query, a touch browser may leave :hover styles "stuck" on an element after a tap, because it emulates hover on touch.
Common errors
- Hiding essential information behind hover. Touch users cannot hover. Tooltips and dropdown menus need a tap or focus alternative.
- Treating a width breakpoint as a touch test. A
max-width: 48emquery does not mean "touch device". Querypointerandhoverinstead. - Removing focus outlines. Keyboard and switch users depend on
:focus-visible. Style it, don't delete it. - Tiny links inside paragraphs. Inline links are hard to tap. For link lists, such as navigation, give each link padding to reach a larger target.
.nav a {
display: inline-block;
padding-block: 0.75rem;
padding-inline: 0.5rem;
}
.nav a:focus-visible {
outline: 2px solid currentColor;
outline-offset: 2px;
}Limits of these queries
The queries report only the primary input. A laptop with a touch screen reports hover: hover and pointer: fine, yet the user may still tap. For that reason, never make the hover state the only way to reach something, and keep touch-friendly sizes in the base styles. The any-hover and any-pointer features report whether any available input can do that. They help when you want to know if a capability exists at all.
Exercise
A button has :hover { background: #e8eefc; } written directly in its base rule. On a phone, the colour stays after the user taps and moves on. How do you fix it using the interaction media features?
Show answer
Move the hover rule into @media (hover: hover) and (pointer: fine) { .button:hover { ... } }. The base rule then stays free of hover styling, and only devices whose primary input can hover precisely get it.