Skip to content
WANCRAFT

E.200Backgrounds & Effects

Fireflies

Glowing fireflies drifting on smooth noise paths, blinking on their own rhythms and gently drawn toward the pointer.

NewReactCanvasTailwindintermediate

Overview

Fireflies fills its container with softly blinking lights. Each one wanders along its own stretch of smooth value noise, blinks on an individual rhythm (a slow rise and fall, then a faint ember until the next pulse), and has a depth that sets its size, brightness and speed, so the swarm reads as layered space. A mouse or pen pointer draws nearby fireflies in, with a sideways swirl so they circle it rather than clump; on touch they gather while a finger is pressed. The glow is a single radial-gradient sprite rendered once per colour and theme — additive on dark themes, a darker amber body with a soft halo on light ones — and every frame is a batch of drawImage calls. Motion runs on fixed 60Hz steps, the canvas is DPR-aware and pauses offscreen and in hidden tabs, and reduced motion shows a still scene.

01Installation

Method 01 · Registry

CLI verified

Uses the shadcn CLI in a project initialised with shadcn init. Installs the file to components/ui/fireflies.tsx and adds its dependencies.

npx shadcn@latest add https://wancraft.my/r/fireflies.json

Method 02 · Copy and paste

  1. 1. No extra dependencies — React and Tailwind CSS only.
  2. 2. Copy the source from the Code tab into components/ui/fireflies.tsx.
  3. 3. Import it and adjust props.
Dependencies
None
Peer
react ≥ 18, tailwindcss ≥ 4
Added
13 Oct 2026
Updated
—

02Usage

The default configuration. Change properties above to generate a tailored example in the Usage tab.

example.tsx
import { Fireflies } from "@/components/ui/fireflies";

export function FirefliesExample() {
  return (
    <div className="relative h-80 w-full overflow-hidden rounded-xl">
      <Fireflies />
    </div>
  );
}

03Props

PropTypeDefaultDescription
countnumber36Number of fireflies.
colorstring"#FFC65C"Glow colour (any CSS colour); deepened to a darker tone on light themes.
sizenumber26Glow diameter of the nearest fireflies in px; the farthest are about 40% of this.
speednumber1Drift speed multiplier; 0 holds them in place while they keep blinking.
attractionnumber0.5How strongly they drift toward the pointer, 0–1 (within 260px).
childrenReactNode—Optional content layered above the fireflies.
...propsHTMLAttributes<HTMLDivElement>—Forwarded to the root, which is absolute inset-0 — place it inside a positioned parent.

04Features

  • 01Smooth value-noise wandering, a different stretch of noise per firefly
  • 02Individual blink rhythms: soft rise and fall, then a faint ember
  • 03Depth sets size, brightness and speed
  • 04Gentle pointer pull with a swirl, so they circle instead of clumping (touch: while pressed)
  • 05Pre-rendered radial glow sprite — no per-frame blur; additive on dark, darker amber on light
  • 06Fixed 60Hz steps, DPR-aware canvas (capped at 2), ResizeObserver, pauses offscreen and in hidden tabs
motion · continuousinput · pointerinput · viewport

05Accessibility

  • The canvas is aria-hidden and ignores pointer events; layered content stays fully interactive.
  • Blinks are slow, small and soft (2.4–6.6s cycles) — no flashing.
  • prefers-reduced-motion renders a single still scene with a fixed mix of bright and dim fireflies.
  • On light themes the glow is deepened to a darker tone so it stays visible on pale backgrounds.

06Limitations

  • Decorative only — it conveys no information and has no keyboard interaction.