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.
Powered by
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:
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.
Prop | Type | Default | Description |
---|---|---|---|
squareSize | number | 4 | Size of each square in pixels (2-8 recommended) |
gridGap | number | 6 | Gap between squares in pixels (3-12 recommended) |
flickerChance | number | 0.3 | Probability of flicker per frame (0-1) |
color | string | "rgb(0, 0, 0)" | Square color (any valid CSS color format) |
width | number | - | Fixed width (auto-detects container if omitted) |
height | number | - | Fixed height (auto-detects container if omitted) |
className | string | - | Additional Tailwind CSS classes |
maxOpacity | number | 0.3 | Maximum 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:
Dot Pattern
Minimalist dot grids with optional glow effects
Grid Pattern
Clean line grids with various styles and animations
Noise
Organic texture patterns with customizable grain
Interactive Grid Pattern
Grid cells that respond to hover interactions
Background Boxes
Isometric grid with colorful hover effects
Squares Background
Floating square elements with smooth animations
Questions developers actually ask
React Fireworks Background
Explosive celebrations that respond to your clicks like the Fourth of July went digital. Build interactive React backgrounds with canvas physics, particle explosions, TypeScript support, and click-to-launch fireworks for Next.js applications with shadcn/ui.
Gradient Animation Background
Flowing gradients that dance like aurora in a digital sky. Build mesmerizing React backgrounds with animated orbs, mouse tracking, TypeScript support, and CSS blend modes for Next.js applications with shadcn/ui.