Sparkles
Beautiful animated particle effects using tsparticles
Installation
npm install @tsparticles/react @tsparticles/engine @tsparticles/slimUsage
import { SparklesCore } from "@/components/ui/sparkles";
export function MyComponent() {
return (
<div className="h-[40rem] w-full bg-black flex flex-col items-center justify-center overflow-hidden rounded-md">
<h1 className="md:text-7xl text-3xl lg:text-9xl font-bold text-center text-white relative z-20">
Your Title
</h1>
<div className="w-[40rem] h-40 relative">
{/* Gradients */}
<div className="absolute inset-x-20 top-0 bg-gradient-to-r from-transparent via-indigo-500 to-transparent h-[2px] w-3/4 blur-sm" />
<div className="absolute inset-x-20 top-0 bg-gradient-to-r from-transparent via-indigo-500 to-transparent h-px w-3/4" />
<div className="absolute inset-x-60 top-0 bg-gradient-to-r from-transparent via-sky-500 to-transparent h-[5px] w-1/4 blur-sm" />
<div className="absolute inset-x-60 top-0 bg-gradient-to-r from-transparent via-sky-500 to-transparent h-px w-1/4" />
{/* Core component */}
<SparklesCore
background="transparent"
minSize={0.4}
maxSize={1}
particleDensity={1200}
className="w-full h-full"
particleColor="#FFFFFF"
/>
{/* Radial Gradient to prevent sharp edges */}
<div className="absolute inset-0 w-full h-full bg-black [mask-image:radial-gradient(350px_200px_at_top,transparent_20%,white)]"></div>
</div>
</div>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | - | Unique identifier for the particles container |
className | string | - | Additional CSS classes |
background | string | "#0d47a1" | Background color of the particles |
particleSize | number | - | Size of individual particles |
minSize | number | 1 | Minimum particle size |
maxSize | number | 3 | Maximum particle size |
speed | number | 4 | Animation speed |
particleColor | string | "#ffffff" | Color of the particles |
particleDensity | number | 120 | Number of particles |
Dependencies
This component requires the following packages:
@tsparticles/react@tsparticles/engine@tsparticles/slimmotion(framer-motion)