Created
April 5, 2026 10:13
-
-
Save trinhvanminh/4acf0da4bacb11d4cfac3a1266652ca5 to your computer and use it in GitHub Desktop.
Appropriate target area
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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; | |
| } | |
| } |
Author
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
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.