# Flickering Grid

> React canvas background of small squares whose opacity flickers at random, with square size, gap, flicker chance, color and radial fade mask props.

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

## When to use

Use it as a calm, living hero or status backdrop; children render on top. For a pointer-reactive backdrop use BackgroundBoxes, for a still pattern use DotPattern.

## Installation

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

```bash
npx shadcn@latest add @minidev/flickering-grid
```

Writes `components/ui/flickering-grid.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/flickering-grid.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 { FlickeringGrid } from "@/components/ui/flickering-grid"
```

From the npm package:

```tsx
import { FlickeringGrid } from "minidev-ui-kit/premium/flickering-grid"
```

## Usage

```tsx
import { FlickeringGrid } from "@/components/ui/flickering-grid"

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

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `squareSize` | `number` | `4` | no | Side of one square in pixels. |
| `gap` | `number` | `6` | no | Space between squares in pixels. |
| `flickerChance` | `number` | `0.4` | no | Chance per second that any one square changes brightness, 0 to 1. |
| `maxOpacity` | `number` | `0.4` | no | Brightest a square can get, 0 to 1. |
| `color` | `string` | `"var(--accent)"` | no | Any CSS colour, including var(--token). Defaults to the accent. |
| `mask` | `"radial" \| "none"` | `"radial"` | no | Fade the grid toward the edges. |
| `className` | `string` | - | no |  |
| `children` | `React.ReactNode` | - | no |  |

## Examples

### Custom content

Children sit above the canvas; size the panel with className and the grid fills whatever is left.

```tsx
<FlickeringGrid className="h-80">
  <div className="flex h-full flex-col items-center justify-center gap-4 px-6 text-center">
    <p className="text-xs font-medium tracking-[0.06em] text-accent-fg uppercase">Lumen infrastructure</p>
    <p className="max-w-[18ch] text-3xl font-medium tracking-[-0.035em] text-balance text-fg">Built for the night the books close</p>
    <Button>Read the architecture <ArrowRightIcon /></Button>
  </div>
</FlickeringGrid>
```

### Bigger squares, another colour

squareSize and gap set the pitch of the grid; color takes any CSS colour, tokens included, and maxOpacity caps the brightness.

```tsx
<FlickeringGrid squareSize={8} gap={8} color="var(--success)" maxOpacity={0.5} className="h-64" />
```

### Slow and edge to edge

mask none drops the radial fade and a low flickerChance makes the squares change only now and then.

```tsx
<FlickeringGrid mask="none" flickerChance={0.12} className="h-56" />
```

## Accessibility

- The canvas is `aria-hidden` and `pointer-events-none`; children render in a `z-10` layer on top.
- Under reduced motion it draws one still frame and never starts the animation loop.

## FAQ

### Will FlickeringGrid slow down my page?

It redraws a canvas at most 30 times a second and stops when it is off screen or the tab is hidden. The canvas resolution is capped at 2x device pixels. Smaller `squareSize` and `gap` mean more squares to draw.

### Why didn't the colour update when I switched theme?

It does update when the `class` or `data-material` attribute on `<html>` changes, because a `MutationObserver` re-reads `color` then. A theme set on another element, or with `data-theme`, is not watched, so remount the grid or change `color`.

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

- [Background Boxes](https://ui.minidev.pro/docs/background-boxes/md): 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.
- [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.
- [Particles](https://ui.minidev.pro/docs/particles/md): React canvas background of drifting particles that repel or attract around the pointer, colored from your accent token and sharp on high density screens.
- [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.
- [Cursor Spotlight Panel](https://ui.minidev.pro/docs/cursor-spotlight-panel/md): A panel whose accent radial spotlight follows the cursor, driven by Framer Motion values without re-renders. It shows a still surface for reduced motion.

---

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