Constellation Background
Canvas particles drifting with links between neighbors, converging toward the cursor as it comes close.
Slowly drifting stars drawn on Canvas 2D, with links automatically forming between nearby points and their opacity decreasing with distance; as the cursor comes close, particles are gently pulled together and linked to the cursor. A built-in ResizeObserver adapts to the size, and the animation pauses automatically when the element leaves the window — a good fit as a decorative background for a hero or a dark section.
Bring this into your project
Run this command in your project folder. The CLI adds the source and dependencies; then follow the usage example below.
npx webberui@latest add constellation-background.enPlayground
Tune the props live — the code snippet updates as you go, so you can dial in the look you want before copying it.
<ConstellationBackground/>
The complete example includes the preview layout and data. Install the component first, then paste this file into your project.
Installation
npx webberui@latest add https://webberui.com/r/constellation-background.en.jsonOr, once registries are configured in components.json, install it as @webberui/constellation-background.
Usage
import { ConstellationBackground } from "@/components/ui/constellation-background";
<ConstellationBackground
particleCount={72}
linkDistance={110}
color="#9db4d6"
className="rounded-3xl bg-slate-950"
>
<div className="px-8 py-24 text-center text-white">
<h1 className="text-4xl font-semibold">Connect ideas into a star chart</h1>
</div>
</ConstellationBackground>Props
| Prop | Type | Default | Description |
|---|---|---|---|
particleCount | number | 64 | Number of particles (stars); 40–120 is recommended depending on the container size |
linkDistance | number | 110 | A link is drawn when two points are closer than this (px), with opacity decreasing with distance |
color | string | "#94a3b8" | Color of the stars and links; accepts any CSS color string |
speed | number | 1 | Drift speed multiplier: 0.5 is calmer, 2 is livelier |
mouseRadius | number | 160 | Cursor attraction radius (px); particles inside it are drawn toward the cursor and linked to it |
children | React.ReactNode | — | Content layered above the starfield (automatically placed on the z-10 layer) |
className | string | — | Forwarded to the outer container |
Accessibility
- The canvas is a purely decorative layer marked
aria-hidden; all informational content is carried bychildren, so assistive technology never reads the particle graphics - When the user has "reduce motion" enabled at the system level, only a single static star chart is rendered — neither the animation loop nor the cursor interaction starts
- When the component leaves the window, an IntersectionObserver automatically pauses
requestAnimationFrame, reducing power draw and background performance load - The cursor attraction is a visual enhancement only and never intercepts clicks (the canvas is set to
pointer-events-none), so interactive elements insidechildrenkeep working as usual