background · WebGL
ParticleField
A field of sparks drifting behind your content that moves aside for the pointer.
WebGL2 vertex-shader particle drift with pointer repel
- WebGL
- Reduced motion: static
- 2.54 KB gzip
- 1 WebGL context
- Layout shift 0.0002
Install
pnpm dlx shadcn@4.21.1 add @frictionborn/particle-field
Playground
import { ParticleField } from "@/components/ui/particle-field";
<ParticleField />In a full example
The full example loads as you scroll to it.
Accessibility
- The poster, scrim and canvas layers are aria-hidden; the root element and children are not. Particle twinkle runs at about 0.3 Hz (sin(phase + time * 1.8) in the vertex shader), well below 3 flashes per second. There is no built-in pause button: pause with the paused prop or the runtime pauseAll()/resumeAll(). The optional scrim lowers background luminance but contrast is not computed; verify text contrast for your colours.
- Keyboard: None; the component has no interactive elements. Poster, scrim and canvas layers are aria-hidden; children keep their own semantics.
- Touch: No pointer listeners are attached when the device does not report pointer: fine. Coarse pointers with low-end hints get the tier 1 poster; other coarse-pointer devices run the drift at tier 2.
- WCAG criteria it is built for: 2.2.2, 2.3.1
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
color | string | "var(--primary, CanvasText)" | Particle CSS colour, resolved from CSS variables or theme tokens and also used for the dot-pattern poster. |
speed | number | 1 | Kinematic drift rate multiplier. |
count | number | 2000 | Target particle count on Tier 3 (clamped to 4,000). Tier 2 renders 35% of it. |
interactive | boolean | true | Enables pointer repulsion; only active when the device reports pointer: fine. |
scrim | boolean | false | Renders a vertical gradient of the host --background token (40% to 75% opacity) over the canvas to lower background luminance behind children. Does not guarantee text contrast; verify for your colours. |
paused | boolean | false | Freezes this instance's particle loop. The global pauseAll() also stops it. |
maxTier | number | 3 | Upper bound on the capability tier (0 to 3); the tier is the minimum of this and the runtime tier. |
reducedMotion | boolean | none | Optional. No default (follows prefers-reduced-motion). true forces the static poster. false only skips the prop-level check: under prefers-reduced-motion the runtime tier is still 0, so WebGL still does not start. Leave unset. |
className | string | "" | Extra classes on the root div (the built-in class fb-particle-field is kept). |
style | React.CSSProperties | none | Optional. No default. Inline styles on the root div, merged after the built-in layout and background (consumer wins). |
ref | React.Ref<HTMLDivElement> | none | Receives the root <div> that holds the poster and the canvas. |
children | React.ReactNode | none | Optional. No default. Content layered above the poster, canvas and scrim. |
palette | "fire" | "ice" | "neon" | "mono" | "custom" | none | Colours from a palette (DESIGN.md A8): fire, ice, neon, mono, or custom (reads --fb-heat-0..4). Overrides color; leave it out to keep the host's tokens. |
Measured on the bench
Measured by the automated bench at commit 801163e on 2026-10-21. These numbers are written by the bench, never by hand.
| Measure | Result |
|---|---|
| Size, gzip | 2.54 KB at load, 3.48 KB loaded later |
| Layout shift | 0.0002 |
| Frames when nothing should move | off screen 0, hidden tab 0, reduced motion 0 |
| axe accessibility scan | 0 serious, 0 critical |
Browsers it ran in
Automated Playwright runs, some with device emulation. Results from physical phones and tablets are still pending, so none are listed.
| Environment | Tier | Result | Date | Notes |
|---|---|---|---|---|
| Chromium Desktop (SwiftShader) | 3 | pass | 2026-10-21 | 20 passed, 0 failed |
| Chromium Mobile (Pixel 7 emulation) | 2 | pass | 2026-10-21 | 19 passed, 0 failed |
| Firefox Desktop | 3 | pass | 2026-10-21 | 17 passed, 0 failed |
| WebKit Desktop | 3 | pass | 2026-10-21 | 17 passed, 0 failed |
| WebKit Mobile (iPhone 14 emulation) | 2 | pass | 2026-10-21 | 17 passed, 0 failed |
On different devices
Reduced motion (static): Renders the static CSS dot-pattern poster with no WebGL context and no animation frames. Under prefers-reduced-motion the runtime tier is 0, so WebGL does not start.
| Tier | What it does |
|---|---|
| T3 Full | WebGL2 at DPR <= 2.0 with `count` particles, up to 4,000 (fine pointer with hover, no low-end hints) |
| T2 Standard | WebGL2 at DPR <= 1.5 with 35% of `count` particles (coarse pointer without low-end hints, or fine pointer with low-end hints or viewport < 480px) |
| T1 Lite | CSS dot-pattern poster only (coarse pointer with low-end hints: deviceMemory <= 2 or <= 4 cores) |
| T0 Static | CSS dot-pattern poster only, no WebGL (server render, prefers-reduced-motion, Save-Data, no WebGL2, or frame-guard downgrade) |
Content Security Policy
- Works without
'unsafe-eval'. - Needs no reveal gate.
- Sets inline
styleattributes, so allowstyle-src-attr 'unsafe-inline'.