Skip to content

Instantly share code, notes, and snippets.

@trinhvanminh
Created April 5, 2026 10:13
Show Gist options
  • Select an option

  • Save trinhvanminh/4acf0da4bacb11d4cfac3a1266652ca5 to your computer and use it in GitHub Desktop.

Select an option

Save trinhvanminh/4acf0da4bacb11d4cfac3a1266652ca5 to your computer and use it in GitHub Desktop.
Appropriate target area
@utility touch-hitbox {
position: relative;
&::before {
content: "";
position: absolute;
display: block;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
height: 100%;
min-height: 44px;
min-width: 44px;
z-index: 9999;
}
}
@trinhvanminh

Copy link
Copy Markdown
Author

Sometimes you can have a button that is visually quite small which makes it harder to tap on touch devices. The fix here is to use a ::before pseudo-element to create a larger hit area without changing the layout.

Apple recommends that interactive elements should have a minimum hit target of 44px. WCAG recommends the same size. Knowing this, and knowing that (almost) everyone uses Tailwind these days, we can create a touch-hitbox utility.

@trinhvanminh

Copy link
Copy Markdown
Author
<button className="touch-hitbox">
  <BellIcon />
</button>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment