GodUI

Pixel Grid

A grid of squares that flicker their opacity — as an automatic animated background, or revealed only under the cursor.

A field of small squares that flicker their opacity on a loop. It has two modes. With interactive={false} the whole field flickers on its own — an automatic animated background. With interactive, only the squares within interactionRadius of the cursor animate; the rest are hidden or held at a static dim, depending on cursorReveal. Drop it as the first child of a relative overflow-hidden container; your content sits above it. The square color defaults to the --color-foreground theme token and re-resolves on theme change, so it tracks light and dark automatically.

Installation

pnpm dlx shadcn@latest add "https://godui.design/r/pixel-grid.json"

Usage

tsx
 
import { PixelGrid } from "@/components/godui/pixel-grid";

PixelGrid is absolutely positioned and fills its nearest positioned ancestor, so that parent must be relative. Add overflow-hidden to keep the edges clean.

tsx
 
<div className="relative overflow-hidden">
  <PixelGrid interactive={false} />
</div>

Examples

Cursor reveal

Set interactive so only the squares within interactionRadius of the cursor animate. With the default cursorReveal="hidden", the rest stay invisible — a spotlight that follows the pointer.

Move your cursor across the grid

Cursor reveal over a dim field

cursorReveal="dim" keeps the squares outside the radius visible at a static low opacity, so the cursor lights up an already-present grid.

Move your cursor across the grid

Custom color

Pass any CSS color string to color to override the theme token.

Dense grid

Smaller squareSize and gridGap pack the field tighter.

Props

PropTypeDefaultDescription
squareSizenumber4Side length (px) of each square.
gridGapnumber6Gap (px) between squares.
flickerChancenumber0.3Per-second probability a square re-rolls its opacity.
colorstring--color-foregroundSquare color, any CSS color string. Defaults to the theme token.
maxOpacitynumber0.3Upper bound on square opacity (0–1).
interactivebooleantruefalse flickers the whole field automatically; true animates only squares within the cursor radius.
interactionRadiusnumber120Radius (px) of the cursor reveal.
interactionStrengthnumber1How strongly the cursor reveals squares within the radius (0–1).
cursorReveal"hidden" | "dim""hidden"How squares outside the radius render in interactive mode — invisible, or a static dim.
widthnumberFixed width (px). Defaults to filling the parent.
heightnumberFixed height (px). Defaults to filling the parent.

Also accepts standard div attributes (e.g. className, style).

Honors prefers-reduced-motion: the flicker animation pauses and a single static frame is drawn instead.

On this page

Built with GodUI

Beautifully crafted motion components for modern interfaces.

Star on GitHub