Sparkles field, animated React component
A canvas layer of sparkles that pop in with a small overshoot, turn as they shine, drift and fade, then reappear elsewhere. With interactive on, the pointer leaves a sparkling trail and a click throws a burst that arcs down under gravity.
- Free
- Motion Effects
- Hover
Like Sparkles field? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Sparkles field stays free.
Play with it
Move the controls and watch it change. Copy code gives you a snippet with only the props you changed.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| count | number | 36 | Base number of sparkles, before density scales it. |
| color | string | — | Sparkle colour. Defaults to blue on light, ice white on dark. |
| minSize | number | 0.9 | Smallest sparkle radius in px. |
| maxSize | number | 2.8 | Largest sparkle radius in px. The biggest fifth are drawn as four-point stars. |
| speed | number | 1 | Speed multiplier for twinkling and drift. |
| opacity | number | 0.9 | Overall opacity, 0.1 to 1. |
| className | string | — | Classes for layout and masking. |
| background | boolean | false | Mount as an absolute layer filling the parent. |
| density | "low" | "medium" | "high" | "medium" | Density preset that scales count. |
| direction | "up" | "down" | "random" | "random" | Which way sparkles drift while they shine. |
| enableGlow | boolean | true | Soft bloom round each sparkle. |
| interactive | boolean | false | Pointer trail and click bursts. |
| autoplay | boolean | false | Throws a few bursts until someone touches the layer. |
Add it to your project
- 1
Set up your project once
You need a Next.js project with Tailwind CSS and the
@/import alias. In its root folder, run this once. It createscomponents.jsonand thecn()helper insrc/lib/utils.ts:npx shadcn@latest init -d
Starting from nothing? The Quick Start walks through the whole thing.
- 2
Connect the registry
Run this once per project. It writes the Nexus UI entry into
components.jsonfor you:npx shadcn@latest registry add "@nexus-labs=https://www.nexus-ui.com/api/registry/{name}"Type it exactly as shown.
{name}is filled in by the CLI with the component you ask for, so you never replace it.
- 3
Add the component
Run this from your project root. It adds the component, the helpers it imports and its npm packages.
npx shadcn@latest add @nexus-labs/sparkles
- 4
Check what was added
With a project made as in the Quick Start (a
src/folder), these files land in it:components/sparkles.tsxsparkles/index.tssparkles.tsx - 5
Copying by hand? Skip the registry
Instead of steps 2 and 3 you can copy the files yourself, with no registry and no API key. Step 1 still applies, so that
cn()exists. Install the packages:npm install framer-motion
Then show the source and create each file at the path it gives:
- 6
Use it in a page
Installing only adds the files. Import the component in a page and render it. The Usage tab on the preview shows a fuller example with props:
// src/app/page.tsx import { Sparkles } from "@/components/sparkles"; export default function Page() { return ( <main> <Sparkles /> </main> ); }
Like Sparkles field? 256 more are in Pro.
Pro unlocks all 256 Pro components, every template and block, and everything we release next. Sparkles field stays free.
About Sparkles field
The Sparkles component renders a field of randomly positioned, rotating star particles around its children. Particle positions, sizes, rotations, and colors are individually randomized on mount and re-randomized on a configurable timer using CSS animation. The effect creates a celebratory or magical visual context around headings, buttons, or icons. Zero JavaScript animation overhead during steady state — particles run on CSS keyframes after mount.
Good for
- Hero heading decorative effects
- CTA button visual emphasis
- Achievement and reward UI displays
- Promotional banner decorations
Sparkles field questions
How do I install the sparkles effect?
Run `npx shadcn@latest add @nexus-labs/sparkles`. It adds the Sparkles component and installs framer-motion.
How do I use it as a background?
Set `background` and it fills its nearest positioned parent as an absolute layer; otherwise size it with `className`. The page also shows line and starfield variations built from the same component.
Which props change how the particles look?
`count` (36) is scaled by `density` ("low", "medium", "high"). `minSize`/`maxSize`, `speed`, `opacity`, `color`, `direction` ("up", "down", "random") and `enableGlow` shape the rest.
Can it react to the mouse?
Yes. Set `interactive` to add a pointer glow, sparkles on hover and a burst of particles on click. With prefers-reduced-motion on, the particles stay still and dimmed.