# Background Boxes

> React 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.

- Kind: Motion component (Motion)
- Docs: https://ui.minidev.pro/docs/background-boxes
- Source (registry JSON with the full file): https://ui.minidev.pro/r/background-boxes.json
- License: MIT. One file, yours to edit after install.

## When to use

Use it as an interactive hero backdrop; children render on top. For quiet ambient motion use FlickeringGrid or AuroraBackground instead.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/background-boxes
```

Writes `components/ui/background-boxes.tsx` plus the MiniDev files it is built from (button) and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/background-boxes.json`.

### npm package

```bash
npm i minidev-ui-kit lucide-react motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { BackgroundBoxes } from "@/components/ui/background-boxes"
```

From the npm package:

```tsx
import { BackgroundBoxes } from "minidev-ui-kit/premium/background-boxes"
```

## Usage

```tsx
import { BackgroundBoxes } from "@/components/ui/background-boxes"

export function Example() {
  return (
    <BackgroundBoxes />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `density` | `number` | `1` | no | Box density. 1 draws 64px boxes, 2 draws them half the size. |
| `colors` | `string[]` | `["var(--accent)", "var(--accent-2)", ...` | no | Colours the boxes light up in. Any CSS colour, including var(--token). |
| `fade` | `number` | `1.6` | no | Seconds a lit box takes to fade back. |
| `idle` | `number` | `2` | no | Boxes that light on their own each second while nobody hovers. 0 turns the idle flicker off. |
| `skew` | `[number, number]` | `[-24, 12]` | no | Tilt of the grid in degrees: skew along x, then along y. |
| `className` | `string` | - | no |  |
| `children` | `React.ReactNode` | - | no |  |

## Examples

### Custom content

Children sit above the grid and the pointer still lights boxes through them.

```tsx
<BackgroundBoxes className="h-80">
  <div className="flex h-full flex-col items-center justify-center gap-4 px-6 text-center">
    <p className="max-w-[18ch] text-3xl font-medium tracking-[-0.035em] text-balance text-fg">Every deploy, on the record</p>
    <p className="max-w-sm text-sm text-fg-muted">Lumen keeps a signed log of who shipped what, and when.</p>
    <Button variant="outline">Open the deploy log <ArrowRightIcon /></Button>
  </div>
</BackgroundBoxes>
```

### Dense and quick

density 2 halves the box size; a short fade and more idle flickers per second read as a busy board.

```tsx
<BackgroundBoxes density={2} fade={0.6} idle={6} className="h-64" />
```

### Flat, one colour

A zero skew lays the grid flat, one colour keeps it quiet and idle 0 lights boxes only under the pointer.

```tsx
<BackgroundBoxes skew={[0, 0]} colors={["var(--accent)"]} idle={0} className="h-64" />
```

## Accessibility

- The whole grid is `aria-hidden` and 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`).

## FAQ

### 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.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `lucide-react`, `motion`
- Built from: [button](https://ui.minidev.pro/docs/button/md)

## Related

- [Flickering Grid](https://ui.minidev.pro/docs/flickering-grid/md): React canvas background of small squares whose opacity flickers at random, with square size, gap, flicker chance, color and radial fade mask props.
- [Aurora Background](https://ui.minidev.pro/docs/aurora-background/md): React aurora background that drifts soft, blurred bands of accent colour behind a hero, with intensity, speed, blur and colour props. Pauses off screen.
- [Dot Pattern](https://ui.minidev.pro/docs/dot-pattern/md): A dot or grid background drawn as one SVG pattern, faded at the edges, with an optional accent glow that follows the pointer and lights the dots beneath it.
- [Retro Grid](https://ui.minidev.pro/docs/retro-grid/md): React retro grid background: a perspective floor receding to a glowing horizon that scrolls slowly toward the viewer, with angle and cell size props.
- [Animated Feature Row](https://ui.minidev.pro/docs/animated-feature-row/md): A row of feature cards that slide up with a staggered delay when scrolled into view. Pass title and description pairs; reduced motion keeps them still.
- [Card Tilt](https://ui.minidev.pro/docs/card-tilt/md): A card that tilts in 3D toward the pointer on springs, with an accent glare that follows the cursor. It stays flat when reduced motion is preferred.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
