Background

Squares

Interactive animated grid patterns with hover effects and directional movement. Perfect for React applications requiring geometric backgrounds with Next.js integration and TypeScript support.

Powered by

Loading component...

Installation

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

Features

  • Multi-directional animation with smooth scrolling in right, left, up, down, or diagonal directions
  • Interactive hover effects highlighting squares on mouse movement with customizable fill colors
  • Adjustable speed control from subtle slow motion to dynamic fast animations
  • Customizable grid styling configuring square size, border colors, and hover effects
  • Canvas-based rendering using efficient HTML5 Canvas with requestAnimationFrame optimization
  • Responsive adaptation automatically adjusting to container dimensions and window resize
  • Touch-friendly interaction supporting both desktop mouse and mobile touch events
  • TypeScript support with complete interface definitions for reliable integration

Examples

Moving Grid

Loading component...

Use Cases

This free open source React component works well for:

  • Hero section backgrounds - Geometric patterns for modern landing pages built with Next.js
  • Loading screens - Animated grids providing visual interest during data processing using TypeScript
  • Portfolio overlays - Subtle background animations for creative showcases
  • Dashboard interfaces - Professional grid patterns for admin panels using shadcn/ui design
  • Interactive galleries - Hover-responsive backgrounds for image and content displays
  • Brand experiences - Unique geometric animations expressing technical precision using Tailwind CSS

API Reference

Props

PropTypeDefaultDescription
direction"right" | "left" | "up" | "down" | "diagonal""right"Direction of grid movement
speednumber1Animation speed (higher = faster)
borderColorstring"#333"Color of the grid lines
squareSizenumber40Size of each square in pixels
hoverFillColorstring"#222"Fill color when hovering over squares
classNamestring-Additional CSS classes for the canvas

Implementation Notes

  • Component uses HTML5 Canvas API with requestAnimationFrame for smooth 60fps animation
  • Grid automatically adapts to container dimensions and handles window resize events
  • Hover detection optimized for responsiveness across desktop mouse and mobile touch
  • Direction control supports five movement patterns: right, left, up, down, and diagonal
  • Speed parameter ranges from 0 (static) to 2+ (fast) for different animation intensities
  • Square size configurable from 20px (fine grid) to 80px+ (large grid) for visual density control
  • Color customization supports RGBA values for theme integration and opacity control
  • Compatible with shadcn/ui design system and Tailwind CSS utility classes for styling