Skip to content

shadcn.io is an independent project built on shadcn/ui

Pro

Fireflies Background for Svelte

Warm dots wander on curved paths and pulse, each with a soft halo. For Svelte with Ark UI, when a hero needs quiet life behind its copy.

On this page10 sections
UI library: Ark UI

Warm dots wander on curved paths, each with a soft halo and a short streak of light behind it, lighting up and going dark on its own rhythm. They sit at three depths over a faint mist along the bottom. It's a GLSL scene on WebGL2 with no dependency. On a dark surface they're light with a white-hot dot; on a light one, dots of pigment in a deeper tone with a tinted halo. They gather loosely around the pointer, and the ones near it wake up.

Use it behind a hero or a section that should feel like a summer night: travel, outdoors, a quiet product page. For plain dots that drift in depth without blinking, use Particles; for dust in a slanted shaft of sunlight, Pollen; for a night sky with parallax, Starfield. With reduced motion it holds one still frame.

Playground
Fireflies Background, still
Customize

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

<script lang="ts">
import { Fireflies } from "@/components/ui/fireflies";
</script>
<Fireflies class="flex min-h-[32rem] flex-col items-center justify-center">
  <h1 class="text-5xl font-semibold">Cabins where the night still gets dark</h1>
</Fireflies>

Fireflies is a container: whatever you put inside sits on top of the scene, in normal flow. It fills its own box, so give it a height or content. For a backdrop behind the whole page, render it empty with className="fixed inset-0 -z-10".

Presets

Duskthe default lookTry it
<Fireflies />
FairyTry it
<Fireflies
  colors={["#ff9ad5", "#c4a2ff", "#9ad8ff"]}
  hazeColor="#8a4fd0"
  pulse={1.5}
  size={2.6}
  trail={0.9}
/>
LagoonTry it
<Fireflies
  colors={["#5ef2ff", "#7ab8ff", "#a0fff0"]}
  density={2}
  glow={1.2}
  hazeColor="#0e6a8a"
  pulse={0.7}
  size={2.2}
  trail={1}
/>
LanternsTry it
<Fireflies
  colors={["#ffb347", "#ff8a3c", "#ffd08a"]}
  density={0.5}
  glow={1.7}
  haze={0.7}
  hazeColor="#b8503a"
  pulse={0.35}
  size={6}
  trail={0}
  wander={0.5}
/>
MeadowTry it
<Fireflies
  colors={["#d8ff6a", "#b6f25c", "#f2ff9a"]}
  density={1.5}
  hazeColor="#1f8f6f"
  pulse={1.3}
  size={2.5}
/>
MonoTry it
<Fireflies
  colors={["var(--foreground)"]}
  glow={0.5}
  haze={0.25}
  hazeColor="var(--muted-foreground)"
/>
Swarmthe default lookTry it
<Fireflies
  density={3}
  glow={0.6}
  haze={0.2}
  pulse={1.6}
  size={2}
  trail={1}
  wander={2}
/>

Each preset is a set of props, so copy one and keep tuning. Dusk is the default. Meadow turns them yellow-green over a green mist, Lanterns keeps a few large slow lights that barely move, Lagoon is a dense field of blue plankton with long streaks, Swarm packs the box with small fast ones, and Mono takes its color from your theme.

Examples

Hero

The fireflies are small and far apart, so the copy sits in the middle of the box, right over them. The headline and the line under it use the foreground color; the chip and the second button have a translucent ground of their own.

Preview width

Lagoon

Three blues on a dark surface with a teal mist (hazeColor="#0e6a8a"): twice as many (density={2}), smaller (size={2.2}), on a slower rhythm (pulse={0.7}), and with the streak at its longest (trail={1}), so each one draws the bend of its path.

Preview width

In a card

A few large lights that hardly move: size={6}, glow={1.7}, density={0.5}, wander={0.5}, a slow pulse={0.35} and no streak. fade="bottom" thins them out toward the lower edge, where the copy sits.

Preview width

Customization

Every color is a CSS color, so a theme variable works and follows a theme switch: colors={["var(--chart-1)", "var(--chart-2)"]}. Each firefly takes one color of the list, and hazeColor tints the mist. size, glow and trail shape a firefly; density, wander and pulse set how many there are, how far they stray and how often they light.

The surface is the root's own background, bg-background by default. Give the root another (bg-slate-950, an image, a gradient) and the fireflies adapt: they add light to a dark surface and draw as pigment on a light one. fade masks an edge, opacity turns the whole effect down, and grain adds film grain.

<Fireflies
  class="min-h-[32rem] bg-slate-950"
  colors={["var(--chart-1)", "var(--chart-2)"]}
  density={1.5}
  fade="top"
  hazeColor="var(--chart-3)"
/>

Performance

It's one WebGL2 canvas and one fragment shader. The box is cut into cells at three scales, seven cells in ten hold one firefly, and a pixel checks the nine cells around it in each scale: 27 fireflies at most, nearly all of them dropped by a distance test before their path is worked out. The mist is three octaves of simplex noise. The cost doesn't grow with density. It draws only while it's on screen and the tab is visible, shares one frame loop with every other background on the page, and lowers its own resolution if frames run long. quality sets the render scale yourself, and paused holds the frame.

Accessibility

The fireflies are decoration: they're hidden from assistive tech and let every click through to your content. With reduced motion it draws one still frame and ignores the pointer. Nothing flashes: at pulse={1} a firefly lights once every 3 to 7 seconds, takes 0.4 to 0.8 seconds to come on and 1.3 to 2.9 seconds to fade, and travels about 10 pixels a second.

Put copy over it in the foreground color (text-foreground). Measured on the default look, foreground text keeps at least 5:1 on every pixel of a light surface and 14:1 on 99% of them. On a dark surface 99% of the pixels stay above 6.7:1 and no 24-pixel block averages below 5:1; the weak spots are the white-hot dots and the inside of the nearest halos, 0.4% of the pixels. Lower glow or intensity if body copy sits on many of them.

FAQ

How do I change the colors?

Pass one to eight CSS colors to colors. Each firefly takes one of them, so the list is a mix, not a gradient. hazeColor is the mist along the bottom. Hex, oklch() and theme variables such as var(--primary) all work, and a variable follows your theme when it changes. Yellow-green on a green mist reads as a meadow, cyan on teal as glowing plankton.

Does it work on a light page?

Yes, with no prop to set. The scene reads the color behind it. On a dark surface a firefly is light: a white-hot dot in a colored halo. Light can't show on white, so on a light surface the same firefly is a dot of pigment in a deeper tone of its color, with a pale tinted halo, and the mist is a faint tint along the bottom. Set the surface with a class on the component, such as bg-slate-950.

How do I show more or fewer fireflies?

density runs from 0.3 to 3. At 1 there are about 130 in a 1280 by 720 box, and about half of them are lit at any moment; the rest keep a faint ember. pulse sets how often each one lights, and at 0 they all stay lit. size is the radius of the nearest ones' dot in pixels, and glow the strength and width of the halo.

Can I slow them down or make them hover in place?

wander sets how far each firefly strays from its spot: 0 holds it in place, 2 lets it roam across its whole patch. speed scales all the motion, the blinking included, and trail is the streak of light behind a moving one, from none at 0 to a long curved one at 1.

How do I put it behind the whole page?

Render it empty with className="fixed inset-0 -z-10". It still answers the pointer there, since it listens on the window. To put it behind one section, wrap that section's content in it and give it a height, such as min-h-svh. The fireflies are sized in pixels, so a full page shows more of them, not larger ones.

Will it slow my page down?

It's a light shader: at most 27 fireflies checked a pixel, most of them rejected by one distance test, plus three octaves of noise for the mist, and nothing at all while it's off screen or the tab is hidden. If a device can't keep up, it renders fewer pixels by itself. The dots are small, so keep quality at 0.75 or above.

Does it work with Next.js and server components?

Yes. Import it into a server component and it renders its box and your content on the server; the canvas starts in the browser and fades in over the surface. It needs WebGL2, which every current browser has. Without it the box keeps its background, or the fallback you pass.

What happens with reduced motion?

It draws one still frame, with fireflies at every stage of lighting up and fading, and stops. The pointer no longer gathers them. The frame is the same one every time, so the page looks the same on each visit.

API Reference

Fireflies

data-slot="fireflies"

PropType
colors?string[]

One to eight CSS colors; each firefly takes one of them. Theme variables such as var(--primary) follow your theme.

Default
["#ffc24d", "#ffb347", "#ff9f4a"]
density?number

How many fireflies there are, from 0.3 to 3: 1 puts about 130 in a 1280 by 720 box, with about half of them lit at any moment.

Default
1
fade?"none" | "radial" | "top" | "bottom" | "left" | "right"

Which edges fade out to the surface: radial keeps the middle, the others name the side that fades.

Type
"none" | "radial" | "top" | "bottom" | "left" | "right"
Default
"none"
fallback?string

What shows until the first frame and in browsers without WebGL2: a CSS background value that looks like the scene.

glow?number

How strong and how wide the halo around each firefly is, from 0 (a bare dot) to 2.

Default
1
grain?number

Film grain over the scene, from 0 to 1.

Default
0
haze?number

How thick the mist along the bottom is, from 0 to 1.

Default
0.5
hazeColor?string

The color of the mist, as any CSS color.

Default
"#6b5bd6"
intensity?number

How bright the fireflies are, from 0 to 2.

Default
1
interactive?boolean

Whether the scene follows the pointer and answers a press. Touch never moves it, so scrolling a page on a phone isn't disturbed.

Default
true
opacity?number

How strongly the scene shows over the surface, from 0 to 1.

Default
1
paused?boolean

Holds the current frame.

Default
false
pulse?number

How often each firefly lights up, from 0 (they all stay lit) to 2: at 1 it's once every 3 to 7 seconds.

Default
1
quality?number

Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). Lower is cheaper and softer.

Default
1
size?number

The radius of the nearest fireflies' dot, in pixels, from 1.5 to 6. The ones further back are smaller.

Default
3
speed?number

Animation speed: 1 is normal, 0 holds the frame.

Default
1
time?number

A fixed moment, in seconds: draws it and doesn't animate.

trail?number

How long the streak of light behind a moving firefly is, from 0 (a dot) to 1.

Default
0.5
wander?number

How far each firefly strays from its spot, from 0 (it hovers in place) to 2.

Default
1