Skip to content

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.json

Build 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.

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.

Props

PropTypeDefaultDescription
densitynumber1.4How many particles per 10,000 px² of the field (a 1000 x 600 field at 1 draws 60). The count is always capped by maxCount, and halved on devices with little memory, few cores or Save-Data.
maxCountnumber120The most particles ever drawn, whatever the density and the size of the field.
radiusnumber2Radius of a particle in px; each one varies a little around it.
speednumber10Sets the drift speed in px per second.
pointerParticlesPointer"repel"What a nearby pointer does: push particles away softly, draw them in, or nothing. Only mouse and trackpad react; touch screens and reduced motion never do.
pointerRadiusnumber120Distance in px within which the pointer moves particles.
colorstring"var(--sheen-accent)"Sets the colour of most particles, any CSS colour.
colorTostring"var(--sheen-accent-2)"Colour of the rest (about a third), any CSS colour.
pausedbooleanfalseHold the particles where they are (they carry on from there when unpaused).
seednumber1Seed for the starting positions, so a field looks the same on every visit and on the server.
classNamestringNoneAdds extra classes to the overlay. Size it with inset-0 inside a relative parent, or give it its own size.
styleCSSPropertiesNoneApplies an inline style to the overlay.

Keyboard

KeysAction
TabNot focusable: the canvas is click-through and never takes focus.

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

19 effects pages in all: browse them on All effects.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .