The ParticleBackground component creates stunning animated backgrounds with flowing particles, dots, and lines , perfect for hero sections, landing pages, and immersive experiences
Installation
1npx shadcn@latest add "https://ace-ui-six.vercel.app/r/particle-background.json"
Usage
1import { ParticleBackground } from "@/components/particle-background";23export default function Example() {4return (5 <div className="relative w-full min-h-screen flex items-center justify-center text-white overflow-hidden">67 <ParticleBackground8 direction="left-to-right"9 speed={50} // 50 pixels per second10 maxParticles={150}11 dotsEnabled={true}12 dotColor="#a78bfa" // Purple dots13 dotSize={2}14 dotOpacity={0.6}15 linesEnabled={true}16 lineColor="#60a5fa" // Blue lines17 lineWidth={1}18 lineLength={8}19 lineOpacity={0.5}20 backgroundColor="#0f0f0f" // Dark background21 glow={true}22 fadeEdges={true}23 />24 </div>25);26}
Features
- Six movement directions: left-to-right, right-to-left, top-to-bottom, bottom-to-top, diagonal
- Separate customization for dots and lines (colors, sizes, opacity)
- Responsive canvas that adapts to screen size and device pixel ratio
- Optional glow effects for enhanced visual appeal
- Edge fading effect for seamless integration
- Configurable particle count and animation speed
Props
| Prop | Type | Default | Description |
|---|---|---|---|
direction | 'left-to-right' | 'right-to-left' | 'top-to-bottom' | 'bottom-to-top' | 'diagonal-tl-br' | 'diagonal-tr-bl' | 'left-to-right' | Direction of particle movement |
speed | number | 50 | Particle movement speed in pixels per second |
maxParticles | number | 150 | Total number of particles on screen |
dotsEnabled | boolean | true | Whether to show dot particles |
dotColor | string | '#a78bfa' | Color of dot particles (hex/rgb/hsl) |
dotSize | number | 2 | Maximum size of dot particles in pixels |
dotOpacity | number | 0.6 | Opacity of dot particles (0-1) |
linesEnabled | boolean | true | Whether to show line particles |
lineColor | string | '#60a5fa' | Color of line particles (hex/rgb/hsl) |
lineWidth | number | 1 | Width/thickness of line particles in pixels |
lineLength | number | 10 | Maximum length of line particles in pixels |
lineOpacity | number | 0.5 | Opacity of line particles (0-1) |
backgroundColor | string | '#0f0f0f' | Background color of the canvas |
glow | boolean | true | Whether to add glow/shadow effects to particles |
fadeEdges | boolean | true | Whether particles fade out near canvas edges |
Direction Options
The component supports six different movement directions:
- left-to-right: Particles flow from left edge to right edge
- right-to-left: Particles flow from right edge to left edge
- top-to-bottom: Particles flow from top edge to bottom edge
- bottom-to-top: Particles flow from bottom edge to top edge
- diagonal-tl-br: Particles flow diagonally from top-left to bottom-right
- diagonal-tr-bl: Particles flow diagonally from top-right to bottom-left
Performance Tips
- Lower
maxParticlesfor better performance on mobile devices - Disable
gloweffects for improved performance - Use solid colors instead of gradients when possible
- Consider reducing
speedfor smoother animations on lower-end devices