Background

Particles

Interactive particles component with mouse tracking and customizable animations using HTML5 Canvas.

Loading component...

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

Features

  • Mouse Interaction: Particles respond to mouse movement with magnetic attraction
  • Canvas-based Animation: Smooth 60fps animations using HTML5 Canvas
  • Customizable Properties: Control quantity, size, color, speed, and behavior
  • Performance Optimized: Efficient particle system with automatic cleanup
  • Responsive Design: Adapts to container dimensions with automatic resize handling
  • TypeScript Support: Fully typed with comprehensive interface definitions

Examples

Interactive Experience

Loading component...

API Reference

Particles

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the container
quantitynumber100Number of particles to render
staticitynumber50Controls how much particles are affected by mouse
easenumber50Easing factor for particle movement
sizenumber0.4Base size of particles
refreshbooleanfalseForces particles to regenerate when true
colorstring"#ffffff"Hex color code for particles
vxnumber0Horizontal velocity bias for particles
vynumber0Vertical velocity bias for particles

Usage Notes

  • The component uses absolute positioning and should be placed within a relative container
  • Content should have a higher z-index to appear above the particles
  • Particles automatically regenerate when they move outside the canvas bounds
  • Mouse interaction is calculated relative to the canvas center
  • The component is optimized for performance with requestAnimationFrame
  • Edge detection ensures particles fade near container boundaries for smooth visual transitions

Customization

You can customize the particle behavior by adjusting the props:

  • Magnetic Effect: Lower staticity values make particles more responsive to mouse movement
  • Smooth Movement: Higher ease values create smoother, slower particle transitions
  • Particle Density: Adjust quantity for more or fewer particles
  • Visual Style: Change color and size to match your design
  • Directional Flow: Use vx and vy to create directional particle movement