Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Hitbox for React and Tailwind

Expand hit areas of interactive elements without affecting layout.

Kudos to Kian Bazza for the original implementation.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/hitbox.json

Usage

<Button className="hitbox-6">Click me</Button>
<Checkbox className="hitbox-4" />
<a href="/page" className="hitbox-y-3 block py-2">Link</a>

Examples

Basic

Use hitbox-* to extend the hit area uniformly on all sides.

Individual sides

Target specific sides with hitbox-l-*, hitbox-r-*, hitbox-t-*, and hitbox-b-*.

Horizontal and vertical

Use hitbox-x-* and hitbox-y-* for axis shorthands.

Custom values

Use arbitrary values with bracket syntax.

Debugging

Add hitbox-debug to visualize the expanded hit area.

Use hitbox-y-* so adjacent items feel continuous.

API Reference

ClassExpansion
hitboxBase (no expansion)
hitbox-*All sides (spacing or [value])
hitbox-l-*Left
hitbox-r-*Right
hitbox-t-*Top
hitbox-b-*Bottom
hitbox-x-*Left and right
hitbox-y-*Top and bottom
hitbox-debugDebug overlay