Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Pro

Flickering Grid Background for React

A grid of small squares that fade in and out at random behind your content, like a wall of status lights. For React with Base UI, when a dashboard, a developer page or a hero needs a quiet, living texture.

Framework

A grid of small squares that change brightness at random, a few at a time, like a wall of status lights. The squares are two small SVG patterns of different sizes laid over each other, so the grid never visibly repeats, and their groups step through opacities on keyframes the install adds to your stylesheet. Nothing runs in the browser.

Use it as a quiet texture behind dashboards, developer pages and heroes. For falling code instead, use Matrix; for dots that don't move, Dot Pattern; for traces with signals running along them, Circuit.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

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

Flickering Grid is a container: give it a size and put your content inside. The grid fills the box behind the content at any size.

<FlickeringGrid className="flex min-h-[420px] items-center justify-center">
  <h1 className="text-5xl font-semibold">Every service, at a glance</h1>
</FlickeringGrid>

For a backdrop behind the whole page, leave it empty and fix it under everything else:

<FlickeringGrid className="fixed inset-0 -z-10" />

Demos

Status lights

cellColor takes any CSS colour, here a green on a dark card, and maxOpacity={0.5} lets the brightest squares glow more.

Preview width

Bigger cells

squareSize={8} and gridGap={8} make larger squares on a wider pitch, and speed={2} changes them twice as often.

Preview width

Accessibility

The grid is decorative: it's hidden from screen readers and lets every click through to your content. With reduced motion the grid holds still, a random speckle. Nothing flashes: each change touches a few scattered squares, well under any flash threshold, even at maxOpacity={1}. The squares use your foreground colour at up to 30% by default, so text on top stays readable; keep maxOpacity at 0.3 or less behind body text.

FAQ

How do I change the density?

squareSize and gridGap set the square and the gap in pixels (4 and 6 by default). The grid is built for those sizes when the page renders.

It flickers too fast or too slow. How do I adjust it?

speed sets how often squares change: at 1 each square changes about every three seconds, at 2 twice as often. maxOpacity caps the brightest square.

Can I change the colour?

cellColor takes any CSS colour. The default follows your theme's text colour, so the grid shows in light and dark; you can also set --flickering-grid-color from your own CSS.

Does it handle thousands of squares?

Yes: the squares are two small repeating SVG tiles, and only 32 groups of them change, each every few seconds. No script runs.

I'm coming from Magic UI's Flickering Grid. What changed?

squareSize, gridGap and maxOpacity work the same. color is cellColor, flickerChance is speed (speed = flickerChance / 0.3), and there are no width or height props: the container sets the size, and you put your content inside it.

What happens with reduced motion?

The grid stays as a still, random speckle.

API Reference

FlickeringGrid

<div> data-slot="flickering-grid"

PropType
cellColor?string

The squares' colour, any CSS colour. @default "var(--foreground)".

gridGap?number

The gap between squares, in pixels. @default 6.

Default
6
maxOpacity?number

How opaque the brightest square gets, from 0 to 1. Keep it at 0.3 or less behind body text.

Default
0.3
speed?number

How often squares change, as a multiplier: 1 is about once every three seconds for each square, 2 twice as often.

Default
1
squareSize?number

The side of one square, in pixels. @default 4.

Default
4
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

CSS variableType
--flickering-grid-colorstring

The squares' colour (var(--foreground)).

--flickering-grid-maxstring

The brightest a square gets (0.3).

--flickering-grid-speedstring

How often squares change, a multiplier (1).

All 100 backgrounds