Background

Flickering Grid

Canvas-based flickering grid animations with performance optimization. Perfect for React applications requiring subtle animated backgrounds with Next.js integration and TypeScript support.

Loading component...

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

Features

  • Canvas-based animation with randomized square opacity changes creating dynamic flickering effects
  • Performance optimized using Intersection Observer to pause animations when not visible
  • High DPI support automatically adapting to device pixel ratio for crisp rendering
  • Customizable grid parameters including square size, gap spacing, and overall dimensions
  • Flexible color system supporting any CSS color format with automatic RGBA conversion
  • Responsive design adapting to container size changes using ResizeObserver
  • Memory efficient implementation using Float32Array for optimal performance
  • TypeScript support with complete interface definitions for reliable integration

Examples

Blue Variant

Loading component...

Use Cases

This free open source React component works well for:

  • Dashboard backgrounds - Subtle animated patterns for data-heavy interfaces built with Next.js
  • Landing page sections - Dynamic grid effects that don't compete with content using TypeScript
  • Portfolio layouts - Sophisticated animated backgrounds showcasing technical skills
  • App interfaces - Ambient grid patterns for modern applications using shadcn/ui design
  • Documentation sites - Technical precision patterns for developer resources
  • Presentation backgrounds - Professional animated effects for slides using Tailwind CSS

API Reference

Props

PropTypeDefaultDescription
squareSizenumber4Size of each square in pixels
gridGapnumber6Gap between squares in pixels
flickerChancenumber0.3Probability of a square flickering per second (0-1)
colorstring"rgb(0, 0, 0)"Color of the squares (any valid CSS color)
widthnumber-Fixed width (uses container width if not specified)
heightnumber-Fixed height (uses container height if not specified)
classNamestring-Additional CSS classes for the container
maxOpacitynumber0.3Maximum opacity for squares (0-1)

Implementation Notes

  • Component uses HTML5 Canvas API for high-performance square rendering and animation
  • Animation automatically pauses when not visible using Intersection Observer for battery efficiency
  • Uses requestAnimationFrame for smooth 60fps animation with automatic container resizing
  • Color formats supported: RGB, hex, HSL, and named CSS colors with automatic RGBA conversion
  • Grid density controlled by squareSize (2-8px) and gridGap (3-12px) parameters
  • Flicker intensity adjustable via flickerChance (0-1) and maxOpacity (0-1) settings
  • Memory efficient implementation using Float32Array for optimal performance on large grids
  • Compatible with shadcn/ui design system and responsive to container dimension changes
  • Pointer events disabled to avoid interference with overlaid content and interactions