Beams Background
A canvas background of beams streaming continuously along a diagonal path, with palette, angle, glow, and cursor-driven acceleration.
npx shadcn@latest add https://webberui.com/r/beams-background.jsonPlayground
Tune the props live — the code snippet updates as you go, so you can dial in the look you want before copying it.
<BeamsBackground />
Installation
npx shadcn@latest add https://webberui.com/r/beams-background.jsonOr, once registries are configured in components.json, install it as @webberui/beams-background.
Usage
import { BeamsBackground } from "@/components/ui/beams-background";
<BeamsBackground
interactive
grain
className="flex h-[420px] items-center justify-center"
>
<h1 className="text-4xl font-bold">Ship in the light.</h1>
</BeamsBackground>The beams are drawn on canvas 2D and driven by requestAnimationFrame, with a rotated coordinate system that makes every beam stream along one shared angle. Foreground content is layered above the beams, and the layout (centering, height, corner radius) goes straight on className.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
beamCount | number | 18 | Number of beams |
colors | string[] | Cool-toned palette | Beam colors, applied by cycling through the list |
angle | number | 14 | Flow direction in degrees — 0 is straight down, positive values lean right |
speed | number | 1 | Flow speed multiplier — higher flows faster |
beamWidth | number | 2 | Base beam width (px); each beam varies randomly around this baseline |
glow | number | 8 | Glow strength: the amount of blur applied to the canvas (px) |
interactive | boolean | false | Beams speed up when the cursor enters the container (mouse only) |
grain | boolean | false | Overlays low-opacity grain to reduce banding across large glows |
children | ReactNode | — | Foreground content layered above the beams |
className | string | — | Container styling (layout, height, corner radius, and so on) |
How it works
- Each beam sweeps along the local Y axis of a rotated coordinate system, which is why every beam shares one flow direction;
anglemerely rotates the whole field, so it costs nothing in performance. - Beam width, length, flow speed, and opacity are all randomly distributed, avoiding the mechanical look of perfect uniformity;
glowsoftens the image with a GPU-accelerated CSSfilter: blurrather than blurring beam by beam. - Each beam's color is taken by cycling through
colors, so the palette length does not need to matchbeamCount. - The canvas scales with
devicePixelRatio(capped at 2x) and draws in CSS pixels, with aResizeObserverwatching the container size and redrawing automatically.
Accessibility
- When the user has "reduce motion" enabled at the system level, only a single static frame of beams is drawn, the animation loop never starts, and cursor interaction is disabled.
- The entire beam layer carries
aria-hiddenandpointer-events-none— decorative only, so it interferes with neither clicks on nor announcement of the foreground content. - On unmount the component cleans up its
requestAnimationFrameandResizeObserver, leaving no background loop behind.
Particle Field
An interactive particle field — particles drift freely and link up when they get close, with a cursor that repels or attracts them, drawn on canvas 2D.
Grain Overlay
A canvas grain overlay that flickers frame by frame, in fine / coarse / vintage textures, adding film-like noise to gradients and images.