Back to EffectsYou are on Particles.

Particles

A burst of particles around a trigger, for likes and stars.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
particles.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/effects/particles.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/particles.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
particles.tsx
"use client";

import * as React from "react";
import { AnimatePresence, motion, type HTMLMotionProps } from "motion/react";
import { cn } from "@/lib/utils";
import { useReduceMotion } from "../motion";
import { useInViewEffect } from "./shared";

type Side = "top" | "bottom" | "left" | "right";
type Align = "start" | "center" | "end";

type ParticlesContextValue = {
  animate: boolean;
  inView: boolean;
};

const ParticlesContext = React.createContext<ParticlesContextValue | null>(null);

export type ParticlesProps = HTMLMotionProps<"div"> & {
  animate?: boolean;
  inView?: boolean;
  inViewOnce?: boolean;
  inViewMargin?: string;
  children: React.ReactNode;
};

export function Particles({
  animate = true,
  inView = false,
  inViewOnce = true,
  inViewMargin = "0px",
  children,
  className,
  style,
  ...props
}: ParticlesProps) {
  const ref = React.useRef<HTMLDivElement>(null);
  const visible = useInViewEffect(ref, inView, inViewOnce, inViewMargin);
  const value = React.useMemo(
    () => ({ animate, inView: visible }),
    [animate, visible],
  );

  return (
    <ParticlesContext.Provider value={value}>
      <motion.div
        ref={ref}
        data-slot="particles"
        className={cn("relative", className)}
        style={style}
        {...props}
      >
        {children}
      </motion.div>
    </ParticlesContext.Provider>
  );
}

export type ParticlesEffectProps = Omit<HTMLMotionProps<"div">, "children"> & {
  side?: Side;
  align?: Align;
  count?: number;
  radius?: number;
  spread?: number;
  duration?: number;
  holdDelay?: number;
  sideOffset?: number;
  alignOffset?: number;
  delay?: number;
  size?: number;
  color?: string;
};

export function ParticlesEffect({
  side = "top",
  align = "center",
  count = 6,
  radius = 30,
  spread = 360,
  duration = 0.8,
  holdDelay = 0.05,
  sideOffset = 0,
  alignOffset = 0,
  delay = 0,
  size = 4,
  color = "currentColor",
  className,
  style,
  ...props
}: ParticlesEffectProps) {
  const context = React.useContext(ParticlesContext);
  const animate = context?.animate ?? true;
  const isInView = context?.inView ?? true;
  const reduce = useReduceMotion();

  const vertical = side === "top" || side === "bottom";
  const alignPercent = align === "start" ? "0%" : align === "end" ? "100%" : "50%";

  const top = vertical
    ? side === "top"
      ? `calc(0% - ${sideOffset}px)`
      : `calc(100% + ${sideOffset}px)`
    : `calc(${alignPercent} + ${alignOffset}px)`;

  const left = vertical
    ? `calc(${alignPercent} + ${alignOffset}px)`
    : side === "left"
      ? `calc(0% - ${sideOffset}px)`
      : `calc(100% + ${sideOffset}px)`;

  const fullCircle = spread % 360 === 0;
  const step =
    (spread * (Math.PI / 180)) / (fullCircle ? Math.max(1, count) : Math.max(1, count - 1));

  const active = animate && isInView && !reduce;

  return (
    <AnimatePresence>
      {active
        ? Array.from({ length: count }).map((_, index) => {
            const angle = index * step;
            const x = Math.round(Math.cos(angle) * radius * 100) / 100;
            const y = Math.round(Math.sin(angle) * radius * 100) / 100;
            return (
              <motion.div
                key={index}
                {...props}
                aria-hidden="true"
                className={cn("pointer-events-none absolute z-10 rounded-full", className)}
                style={{
                  top,
                  left,
                  width: size,
                  height: size,
                  marginLeft: -size / 2,
                  marginTop: -size / 2,
                  background: color,
                  ...style,
                }}
                initial={{ scale: 0, opacity: 0, x: 0, y: 0 }}
                animate={{
                  x,
                  y,
                  scale: [0, 1, 0],
                  opacity: [0, 1, 0],
                }}
                transition={{
                  duration,
                  delay: delay + index * holdDelay,
                  ease: "easeOut",
                  ...(props.transition as object),
                }}
              />
            );
          })
        : null}
    </AnimatePresence>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/particles.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

particles.tsx
import { Particles, ParticlesEffect } from "@/components/prequelui/effects/particles";

export default function Demo() {
  const [burst, setBurst] = useState(0);
  return (
    <Particles>
      <button onClick={() => setBurst((value) => value + 1)}>Celebrate</button>
      <ParticlesEffect key={burst} side="top" count={10} radius={48} color="#f5b301" />
    </Particles>
  );
}
import { Particles } from "@/components/prequelui/particles";

export function Variant() {
  return (
    <Particles tempo={1.2}>
      …
    </Particles>
  );
}
03

Animation

A particles container coordinates a burst of dots around itself. Each dot leaves from one side of the container, travels to its place on a circle and shrinks back to zero, with a small stagger between neighbours.

  • Default travel: 0.8 s ease-out with a 50 ms step between particles.
  • Side and align place the burst on any edge or corner of the container.
  • The burst only plays when the container is in view and motion is allowed.
  • Particles are decorative, aria-hidden and pointer-events none.
800 ms ease-out50 ms staggerradius 30 pxaria-hidden
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

Particles

PropTypeDefault
animatebooleantrue
inViewbooleanfalse
inViewOncebooleantrue
classNamestring—

ParticlesEffect

PropTypeDefault
side"top" | "bottom" | "left" | "right""top"
align"start" | "center" | "end""center"
countnumber6
radiusnumber30
spreadnumber360
durationnumber0.8
holdDelaynumber0.05
sizenumber4
colorstring"currentColor"

Next component

Scroll Fade

Container edges that fade only where there is more content.