Particles Background for React
Particles is a React canvas effect: a capped field of small drifting lights that lean softly away from the pointer. Use it behind a hero or glass card; it draws one still frame under reduced motion.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/particles.jsonBuild something calm
The field is switched off.
Behind glass
The particles are what the glass blurs, which makes the frosted card read as real. Move the mouse over it: nearby particles ease away (or towards the pointer), then settle back. Touch screens and reduced motion never react to the pointer.
Build something calm
A soft field of light behind frosted glass.
import { useState } from "react";
import { GlassCard } from "@/components/sheenui/glass-card/glass-card";
import { Particles } from "@/components/sheenui/particles/particles";
import { Switch } from "@/components/sheenui/switch/switch";
// Package build (after the first npm release, or a packed tarball): import { GlassCard, Particles, Switch } from "@sheenui/theme";
// This example also uses glass-card, switch: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json https://lokendra-builds.github.io/sheenui/r/switch.json
export function Example() {
const [paused, setPaused] = useState(false);
return (
<>
<Switch label="Pause" checked={paused} onCheckedChange={setPaused} />
<div className="relative grid min-h-80 w-full place-items-center overflow-hidden rounded-sheen-xl">
<Particles density={1.4} pointer="repel" paused={paused} />
<GlassCard className="relative max-w-xs p-6 text-center">
<h2 className="text-lg font-semibold">Build something calm</h2>
<p className="mt-1 text-sm text-sheen-fg-muted">A soft field of light behind frosted glass.</p>
</GlassCard>
</div>
</>
);
}Files to copy
5 folders · 6 files · 4 packages
- From
theme/src/ components/particles/lib/{canvas-effects.ts, cn.ts}hooks/{use-media-query.ts, use-preferences.ts}motion/{beat.ts, gate.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/particles.jsonRegistry item: particles. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/glass-card/components/switch/hooks/{use-direction.ts, use-latest.ts}motion/{light-follower.ts, tokens.ts}lib/{field-control-shell.tsx, form.ts, heading.ts, motion-props.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json https://lokendra-builds.github.io/sheenui/r/switch.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Dense and capped
density is particles per 10,000 px². Raise it as far as you like: maxCount is the hard ceiling (120 by default, 400 at most), and devices with little memory, few cores or Save-Data draw half.
import { Particles } from "@/components/sheenui/particles/particles";
// Package build (after the first npm release, or a packed tarball): import { Particles } from "@sheenui/theme";
export function Example() {
return (
<div className="relative min-h-56 w-full overflow-hidden rounded-sheen-xl">
<Particles density={6} maxCount={90} radius={1.2} speed={6} pointer="none" />
</div>
);
}Props
Keyboard
Accessibility
- Decorative: the layer is aria-hidden and carries no information. Particles are small and low in contrast so text above stays readable.
- Offer paused as a control where the field sits behind long reading (WCAG 2.2.2). It also rests off-screen and in hidden tabs.
- Reduced motion draws one still frame, with no loop and no pointer reaction. Colours are the accent tokens read from the page, redrawn when the theme or style preset changes.
- Cost: one canvas on the shared ambient beat (about 30 Hz, fewer while scrolling), device pixel ratio capped at 2, count capped and halved on weak devices.
When to use the particles effect
- Use it behind a hero or a glass card for depth: the particles are what the glass blurs, which makes frosted panels look real without a photo.
- Use it on a landing section that needs a calm, living background; keep density low and let the text carry the page.
- Set pointer to attract or none to change how it answers the cursor; only a mouse or trackpad reacts, never touch.
- Skip it behind long reading or dense tables; a moving field competes with text, so use paused or leave it out.
- Pair it with GlassCard, Backdrop and ShimmerText for a hero that feels layered.
Frequently asked questions
Related pages
19 effects pages in all: browse them on All effects.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .