Skip to content
Gelatin UIAlpha

Hit Area

Free

Grow the touch target of a small control to 44px on touch screens, with no change to the layout.

Tailwind CSS 4MIT + Commons Clause · 1 CSS file · 0 KB JavaScript

24px buttons in a row. Each grows up and down to 44px, so the areas never overlap.

LightDark
Up and downBoth axesSideways
hit-area-y

Install

Add the utility's CSS with the CLI, your coding agent, or by hand. It has no JavaScript.

Usage

Put hit-area on each small control, and hit-area-row on a toolbar so neighbors do not overlap. The area grows only on a touch screen, so the layout never moves.

editor-toolbar.tsx

Variants

The target grows only on a touch screen. In a tight row or column, grow one axis, so two targets never overlap. Our Button has hit-area built in.

  • Alonehit-area

    44 × 44 around a small dot or icon.

  • In a rowhit-area-y

    Grows the height only. Or hit-area-row on the parent.

  • In a columnhit-area-x

    Grows the width only. Or hit-area-column on the parent.

Rules

The target is a centered ::after. Keep these things true and it works anywhere.

  1. 1The element does not clipoverflow: hidden on the element cuts the target back to its own size.
  2. 2::after is freeThe class owns the element's ::after. Use ::before for your own decoration.
  3. 3A transformed child gets z-1A transform makes a new layer that would cover the target.
  4. 4The nearest container winshit-area-row inside hit-area-column: the row rule applies to its children.
  5. 5Only a finger grows itA coarse pointer gets the 44px target. A mouse keeps the drawn size.

Options

The classes and the variables of the utility. Set a variable with an arbitrary property, such as [--hit-area-min-height:3rem].

NameKindDefaultDescription
hit-areaclass44 × 44pxGrows the touch area on both axes.
hit-area-y · hit-area-xclass44pxGrows one axis only, for a control in a tight row or column.
hit-area-row · hit-area-columnclass—On a parent: every hit-area inside grows one axis only.
--hit-area-min-width · -heightvariable2.75remThe smallest size of the area.