Join our Discord Community

React Flickering Grid Background

Grid squares that flicker like old CRT monitors having a moment. Build ambient React backgrounds with canvas-based animations, performance optimization, TypeScript support, and subtle visual noise for Next.js applications with shadcn/ui.

Trying to implement subtle grid animations?

Join our Discord community for help from other developers.


Remember those old CRT monitors when they'd flicker and show static? This React component recreates that ambient digital noise, but in a good way. Tiny squares randomly flicker in and out of existence, creating a subtle living texture that suggests activity without being distracting.

Ambient flickering animation

Watch squares randomly appear and fade with organic timing:

Loading component...

Built for React applications with TypeScript and Next.js. The animation runs on HTML5 Canvas using requestAnimationFrame for smooth 60fps flickering. Intersection Observer pauses the animation when off-screen, so your battery doesn't drain powering invisible pixels.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/flickering-grid.json
npx shadcn@latest add https://www.shadcn.io/registry/flickering-grid.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/flickering-grid.json
bunx shadcn@latest add https://www.shadcn.io/registry/flickering-grid.json

Usage

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

export default function Dashboard() {
  return (
    <div className="relative h-screen">
      <FlickeringGrid
        className="absolute inset-0"
        squareSize={4}
        gridGap={6}
        flickerChance={0.3}
        color="rgb(100, 100, 100)"
        maxOpacity={0.2}
      />
      <div className="relative z-10">
        <h1>Your content appears above the flickering</h1>
      </div>
    </div>
  );
}

Why most grid animations feel mechanical

Most developers use CSS animations or simple JavaScript timers. The grid flickers in patterns—predictable, robotic, obviously computer-generated. Some try to randomize with Math.random(), but it's still just uniform distribution. Real static has clustering and gaps.

This React component uses weighted probability for organic flickering. Squares have a flickerChance per frame, but the timing creates natural clusters of activity. Canvas rendering with Float32Array keeps thousands of squares performant. Intersection Observer stops the animation when you're not looking, because why waste CPU on invisible pixels?

Features

  • Canvas-based rendering with Float32Array for thousands of squares
  • Organic flickering patterns using weighted probability timing
  • Performance optimized with Intersection Observer auto-pause
  • High DPI support automatically adapting to device pixel ratio
  • Responsive sizing using ResizeObserver for container changes
  • TypeScript definitions for all animation and visual parameters
  • Memory efficient implementation preventing browser lag
  • shadcn/ui compatible with proper z-index layering

API Reference

FlickeringGrid

Main component for the ambient flickering grid animation.

PropTypeDefaultDescription
squareSizenumber4Size of each square in pixels (2-8 recommended)
gridGapnumber6Gap between squares in pixels (3-12 recommended)
flickerChancenumber0.3Probability of flicker per frame (0-1)
colorstring"rgb(0, 0, 0)"Square color (any valid CSS color format)
widthnumber-Fixed width (auto-detects container if omitted)
heightnumber-Fixed height (auto-detects container if omitted)
classNamestring-Additional Tailwind CSS classes
maxOpacitynumber0.3Maximum square opacity (0-1, lower = more subtle)

Common gotchas

Performance with large grids: Each square is tracked in a Float32Array. Very large containers (4K+ pixels) might impact performance. Consider reducing squareSize or increasing gridGap.

Z-index content layering: Your content needs relative z-10 or higher. The grid sits at base level to avoid interfering with interactions.

Color format flexibility: Supports any CSS color (hex, rgb, hsl, named colors), but gets converted to RGBA internally for opacity manipulation.

Intersection Observer edge cases: Animation pauses when not visible. If you need it always running (for screen recording), you'd need to modify the component.

Canvas sizing on mobile: The grid auto-resizes to container dimensions. On very small screens, reduce squareSize to maintain proper density.

You might also like

Explore other subtle background components for React applications:

Questions developers actually ask