Background Boxes
MotionReact background of skewed hairline boxes: the box under the pointer lights up in colour and fades out, driven by one pointer handler and CSS transitions.
Installation
npx shadcn@latest add @minidev/background-boxes
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/background-boxes.json
Usage
import { BackgroundBoxes } from "@/components/ui/background-boxes"
export function Example() {
return (
<BackgroundBoxes />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| densityBox density. 1 draws 64px boxes, 2 draws them half the size. | number | 1 |
| colorsColours the boxes light up in. Any CSS colour, including var(--token). | string[] | ["var(--accent)", "var(--accent-2)", ... |
| fadeSeconds a lit box takes to fade back. | number | 1.6 |
| idleBoxes that light on their own each second while nobody hovers. 0 turns the idle flicker off. | number | 2 |
| skewTilt of the grid in degrees: skew along x, then along y. | [number, number] | [-24, 12] |
| className | string | - |
| children | React.ReactNode | - |
When to use
Use it as an interactive hero backdrop; children render on top. For quiet ambient motion use FlickeringGrid or AuroraBackground instead.
Accessibility
- The whole grid is
aria-hiddenand only reacts to the pointer, so keyboard and screen reader users get the content alone. - Under reduced motion the idle flicker is off and lit boxes clear instantly (
--bb-fade: 0s).
Frequently asked questions
Do buttons and links on top of BackgroundBoxes still work?
Yes. The pointer handler sits on the outer panel and the grid layer is pointer-events-none, so your content gets clicks while the box under the cursor still lights.
Why is the grid missing from the server HTML?
The grid is measured on the client with a ResizeObserver, so the server renders an empty panel and hydration matches. The boxes appear after the first measure.
How many DOM nodes does it create?
One <div> per box. A 1200 by 360 panel at density={1} (64px boxes) makes about 400, and density={2} makes about four times as many. Lower density for very large panels, and pass idle={0} to turn off the random flicker.
Dependencies
npm
Built from
Examples
Custom content
Children sit above the grid and the pointer still lights boxes through them.
Dense and quick
density 2 halves the box size; a short fade and more idle flickers per second read as a busy board.
Flat, one colour
A zero skew lays the grid flat, one colour keeps it quiet and idle 0 lights boxes only under the pointer.