Join our Discord Community

React Particles Background

Interactive particle systems that respond to mouse movement like magnetic fields. Build dynamic React background components with canvas rendering, physics simulation, customizable behavior, and TypeScript support for Next.js applications with shadcn/ui.

Building interactive physics experiences?

Join our Discord community for help from other developers.


Static backgrounds are dead space. Wasted potential. What if your background could respond to users? React to their movement? This React component creates particle systems with realistic physics—particles that drift naturally but get pulled toward your cursor like iron filings to a magnet.

Interactive particle physics

Watch particles respond to cursor movement with magnetic attraction and natural drift:

Loading component...

Built for React applications with TypeScript and Next.js. Uses HTML5 Canvas with requestAnimationFrame for smooth 60fps physics simulation. Each particle has velocity, position, and responds to mouse proximity with configurable attraction force. Perfect for hero sections, landing pages, or any interface that needs to feel alive.

Installation

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

Usage

import { Particles } from "@/components/ui/particles";

export default function InteractiveHero() {
  return (
    <div className="relative h-screen bg-black overflow-hidden">
      {/* Your content */}
      <div className="relative z-10 flex items-center justify-center h-full">
        <div className="text-center">
          <h1 className="text-6xl font-bold text-white mb-4">
            Interactive Design
          </h1>
          <p className="text-xl text-gray-300">
            Move your cursor to experience the physics
          </p>
        </div>
      </div>
      
      {/* Interactive particles */}
      <Particles
        className="absolute inset-0"
        quantity={100}
        ease={80}
        staticity={50}
        color="#ffffff"
        size={0.8}
      />
    </div>
  );
}

Why most particle systems feel lifeless

Most developers use CSS keyframes to animate dots in circles or straight lines. It's predictable, robotic, obviously programmed. Others use JavaScript libraries that animate with basic math—particles move in perfect curves that look like geometry homework. Some try canvas particles but without physics, just random movement that feels chaotic.

This React component simulates real particle physics. Each particle has position, velocity, and acceleration. Mouse proximity creates attraction forces that feel magnetic. Particles drift naturally when idle, creating organic movement. Canvas rendering with requestAnimationFrame keeps it smooth at 60fps without the overhead of DOM manipulation.

Features

  • Physics-based simulation with position, velocity, and acceleration for realistic movement
  • Magnetic mouse interaction creating attraction forces based on cursor proximity
  • Canvas rendering providing smooth 60fps animation with hardware acceleration
  • Configurable physics parameters controlling attraction, drift, easing, and particle behavior
  • Automatic edge detection with particle regeneration at container boundaries
  • Performance optimized using requestAnimationFrame and efficient canvas operations
  • Responsive container adaptation automatically adjusting to window and container changes
  • TypeScript definitions for all physics parameters and visual customizations
  • Memory efficient implementation preventing performance degradation over time
  • shadcn/ui compatible with proper layering and interaction handling

Examples

Interactive Experience

Advanced demo with mouse tracking and enhanced visual feedback:

Loading component...

API Reference

Particles

Main component for interactive canvas-based particle physics systems.

PropTypeDefaultDescription
classNamestring-Additional CSS classes for the canvas container
quantitynumber100Number of particles to simulate (recommended: 50-200)
staticitynumber50Mouse attraction strength (0=no attraction, 100=strong)
easenumber50Movement smoothing factor (higher=smoother)
sizenumber0.4Particle radius in pixels (0.2-2.0 recommended)
refreshbooleanfalseForce particle regeneration (useful for prop changes)
colorstring"#ffffff"Particle color (hex, rgb, or named CSS colors)
vxnumber0Base horizontal drift velocity (-5 to 5)
vynumber0Base vertical drift velocity (-5 to 5)

Physics Parameters

Understand how particle behavior is controlled:

// Subtle ambient particles
quantity={50} staticity={80} ease={90} size={0.3}

// Interactive magnetic field
quantity={100} staticity={30} ease={60} size={0.8}

// Dense particle cloud
quantity={200} staticity={50} ease={40} size={0.5}

// Flowing directional particles
quantity={75} vx={2} vy={-1} ease={70} size={0.6}

Physics Simulation Details

  • Position tracking: Each particle maintains x/y coordinates and velocity vectors
  • Mouse attraction: Distance-based force calculation creates magnetic pull effect
  • Edge regeneration: Particles respawn at random positions when leaving bounds
  • Easing calculation: Smooth interpolation prevents jarring movement transitions
  • Canvas optimization: Efficient rendering with requestAnimationFrame timing

Common gotchas

Performance with high quantities: Each particle requires physics calculations every frame. 200+ particles might impact performance on older devices. Test on target hardware.

Z-index content layering: Canvas sits behind content by default. Your content needs relative z-10 or higher. If content disappears, check z-index values.

Mouse interaction boundaries: Mouse tracking works within the canvas bounds. Particles outside these bounds won't respond to cursor movement until they drift back in.

Color format flexibility: Supports hex (#ffffff), rgb(), hsl(), and named colors. However, very transparent colors (alpha < 0.1) might be invisible on some backgrounds.

Canvas sizing responsiveness: Canvas adapts to container dimensions. Very small containers (under 200px) might not show particle movement effectively.

Touch device limitations: Mobile devices don't have mouse hover. Particles will drift naturally but won't respond to touch unless the user is actively dragging.

You might also like

Explore other interactive and dynamic background components for React applications:

Questions developers actually ask