Sparkles

Beautiful animated particle effects using tsparticles

Live Preview
Open in

Xui

Motion
@tsparticles/react
@tsparticles/engine
@tsparticles/slim

Installation

npm install @tsparticles/react @tsparticles/engine @tsparticles/slim

Usage

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

PropTypeDefaultDescription
idstring-Unique identifier for the particles container
classNamestring-Additional CSS classes
backgroundstring"#0d47a1"Background color of the particles
particleSizenumber-Size of individual particles
minSizenumber1Minimum particle size
maxSizenumber3Maximum particle size
speednumber4Animation speed
particleColorstring"#ffffff"Color of the particles
particleDensitynumber120Number of particles

Dependencies

This component requires the following packages:

  • @tsparticles/react
  • @tsparticles/engine
  • @tsparticles/slim
  • motion (framer-motion)