Flickering Grid
MotionReact canvas background of small squares whose opacity flickers at random, with square size, gap, flicker chance, color and radial fade mask props.
Installation
npx shadcn@latest add @minidev/flickering-grid
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/flickering-grid.json
Usage
import { FlickeringGrid } from "@/components/ui/flickering-grid"
export function Example() {
return (
<FlickeringGrid />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| squareSizeSide of one square in pixels. | number | 4 |
| gapSpace between squares in pixels. | number | 6 |
| flickerChanceChance per second that any one square changes brightness, 0 to 1. | number | 0.4 |
| maxOpacityBrightest a square can get, 0 to 1. | number | 0.4 |
| colorAny CSS colour, including var(--token). Defaults to the accent. | string | "var(--accent)" |
| maskFade the grid toward the edges. | "radial""none" | "radial" |
| className | string | - |
| children | React.ReactNode | - |
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.
Accessibility
- The canvas is
aria-hiddenandpointer-events-none; children render in az-10layer on top. - Under reduced motion it draws one still frame and never starts the animation loop.
Frequently asked questions
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.
Dependencies
npm
Built from
Examples
Custom content
Children sit above the canvas; size the panel with className and the grid fills whatever is left.
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.
Slow and edge to edge
mask none drops the radial fade and a low flickerChance makes the squares change only now and then.