expanded-touch-target
Expand the interactive hit area of small or sparsely spaced elements (icon buttons, toolbar actions, nav items with gaps) beyond their visual bounds using a pseudo-element overlay. Use when building i
SKILL.mdskills/expanded-touch-target/SKILL.md
GitHubExpanded Touch Target
A CSS technique for enlarging an element's clickable area beyond its visual bounds without affecting layout. The visual element stays the same size; only the hit area grows.
Problem
Small interactive elements — icon buttons, compact actions, closely spaced button groups with gaps — are hard to tap on touch devices and frustrating to click on desktop. WCAG 2.5.8 (Level AAA) recommends a minimum 44×44 CSS pixel target size.
Common workarounds and their downsides:
| Approach | Downside |
|---|---|
Increase padding |
Changes the visual size of the element; breaks spacing |
Wrap in a larger transparent <button> |
Extra DOM nesting; complicates event handling and a11y |
Increase width / height directly |
Disrupts sibling layout; gap between elements changes |
Pattern
Use a pseudo-element with negative inset to extend the hit area outward from the element's bounds:
<button className="relative" aria-label="Close">
<span className="absolute -inset-2" />
<XIcon className="size-4" />
</button>;
The <span> is an empty absolutely-positioned overlay that extends 8px (0.5rem) beyond the button's box in all four directions, becoming the actual click/tap target.
How It Works
| Class | Purpose |
|---|---|
relative on the button |
Establishes a containing block for the pseudo-element |
absolute on the span |
Removes it from flow — no layout impact |
-inset-2 |
Negative inset expands the span 8px past each edge of the button |
The result: the button's visual size is unchanged (still size-4 worth of icon), but its interactive area is (width + 16) × (height + 16) pixels.
Because the overlay is a child of the <button>, clicks on it bubble up to the button naturally — no extra event wiring needed.
Sizing the Expansion
Choose the negative inset value based on how much expansion is needed:
| Class | Expansion per side | Good for |
|---|---|---|
-inset-1 |
4px | Filling small gaps between adjacent buttons |
-inset-2 |
8px | Icon buttons in toolbars |
-inset-3 |
12px | Isolated small icons or sparse layouts |
-inset-x-2 -inset-y-1 |
Asymmetric | Horizontal expansion with tight vertical space |
For per-axis control, use -inset-x-* / -inset-y-* or individual -top-*, -right-*, -bottom-*, -left-*.
Filling Gaps Between Adjacent Buttons
When multiple buttons sit in a row with gap, the whitespace between them is dead zone — clicks in the gap do nothing. Expand each button's hit area to cover the gap:
<div className="flex gap-2">
<button className="relative">
<span className="absolute -inset-1" />
<EditIcon className="size-4" />
</button>
<button className="relative">
<span className="absolute -inset-1" />
<TrashIcon className="size-4" />
</button>
</div>;
With gap-2 (8px) and -inset-1 (4px expansion per side), each button's hit area extends 4px outward, and the two expansions meet in the middle — the gap is fully covered.
When hit areas overlap, the element that is later in DOM order (higher paint order) receives the click. If priority matters, control with z-index.
Alternative: Pseudo-Element Without Extra DOM
If you prefer not to add a <span>, use before: in Tailwind:
<button className="relative before:absolute before:-inset-2" aria-label="Close">
<XIcon className="size-4" />
</button>;
Functionally identical — the ::before pseudo-element acts as the expanded hit surface. The <span> approach is easier to conditionally control (e.g., different inset per breakpoint via props).
When to Use
- Icon-only buttons (
size-4orsize-5icons) that are too small to comfortably tap - Toolbar actions with visual gaps between them
- Navigation items or breadcrumb links in compact layouts
- Any interactive element smaller than 44×44px on touch-capable devices
When NOT to Use
- The element already meets target size requirements via its own padding
- The parent uses
overflow: hiddenthat would clip the expanded area — switch to padding-based sizing instead - Overlapping hit areas cause wrong-target clicks that can't be resolved with
z-index