Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backgrounds

Pro

Lightning Background for React

A thunderstorm sky: heavy clouds drift, light up from inside, and forked bolts strike the ground over faint rain. For React with Base UI, when a launch, a deadline or a weather page needs drama behind its copy.

Framework

A ceiling of heavy cloud drifts across the box in three layers, and the storm never goes quiet: every few seconds the clouds light up from inside, and now and then a forked bolt strikes the ground, dims and strikes again, while faint rain falls under it all. The clouds are noise textures the browser draws once and CSS slides sideways; the bolts are SVG paths seeded once, so the server and the browser draw the same ones; one CSS clock fires every flash in its own slot, so flashes never overlap. It follows your theme: an overcast grey storm on a light page, a blue-black night storm on a dark one.

Use it for a launch or a countdown, a deadline banner or a weather page. For the rain alone, use Rain; for the other storm in this family, Tornado; for glowing tubes that hold steady, Neon; for electricity running in straight traces, Circuit. With reduced motion nothing flashes: the clouds stop, lit by one still bolt.

Preview width

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

import { Lightning } from "@/components/ui/lightning";

The storm fills the box behind whatever you put inside. Give the container a height; for the whole page, render it empty with className="fixed inset-0 -z-10".

<Lightning className="flex min-h-[420px] items-center justify-center">
  <h1 className="text-4xl font-semibold">Strike while it's hot</h1>
</Lightning>

Demos

Colors

glowColor sets the light in the clouds and the bolts' halo, and boltColor their core; here an amber storm at dusk. The card adds the dark class to its own container, so it shows the night storm on a light page too.

Preview width

Heat lightning

bolts={0} keeps every flash inside the clouds, intensity="subtle" dims them, rain={false} clears the air and speed={0.7} slows the storm, for a distant, quieter sky behind a card's copy.

Preview width

Accessibility

The storm is decorative: it's hidden from assistive tech and never takes the pointer, and your content stays on top in normal flow.

Flashing is capped for photosensitive users. Eight flashes share one 24-second cycle, each in its own slot, at least 1.6 seconds after the one before even at the top speed, and each is at most two pulses, so the storm never flashes more than twice in a second. speed is capped at 1.5 in the component, and the stylesheet keeps the cycle at 16 seconds or longer even if a stylesheet sets --lightning-speed higher. With reduced motion nothing flashes at all: the clouds and the rain stop, and one bolt stays on screen, still, with its cloud lit.

Put copy over it in your foreground colour (text-foreground). The sky behind it keeps body text above 4.5:1 at the default intensity in both color schemes; only the instant a bolt crosses the text, a tenth of a second, is brighter. intensity="strong" brightens every flash, so keep small text off it on a dark page.

FAQ

How often does it strike?

Something happens about every three seconds: four strikes and four softer flashes inside the clouds take turns over a 24-second cycle, and the clouds drift the whole time. speed sets the rhythm, capped at 1.5 to stay photosensitive-safe.

Can I have flashes without bolts?

Yes. bolts sets how many of the four strikes fork down as bolts, from 0 to 4; the others light the clouds from inside instead. flash={false} drops the softer flashes between strikes.

How are the bolts drawn?

Each bolt is a jagged channel from the cloud to the ground, made by midpoint displacement, with up to five forks off its upper part. They're seeded once, so they're the same on every visit. branching sets how many forks show, from 0 (a single channel) to 1.

Can I change the colours?

glowColor sets the light in the clouds and the bolts' halo, boltColor the core, any CSS colour. The sky and the clouds follow your theme; for the night storm on a light page, add the dark class to the container.

Is it safe for photosensitive users?

Flashes never overlap and never come more than twice a second, a limit enforced in the component and in the stylesheet, and nothing flashes with reduced motion.

Does it run JavaScript?

No. The clouds and the rain slide with translate and the flashes change only opacity, which the browser composites without repainting. The textures are drawn once; the layers take about 200 MB of GPU memory on a 2× screen, as large textured backgrounds do.

API Reference

Lightning

<div> data-slot="lightning"

PropType
boltColor?string

The bolts' core colour, any CSS colour.

Default
"oklch(0.985 0.015 280)"
bolts?number

How many of the strikes fork down to the ground as bolts, from 0 to 4; the others light the clouds from inside.

Default
4
branching?number

How much each bolt forks, from 0 (a single channel) to 1 (five forks).

Default
0.6
flash?boolean

The softer flashes deep in the clouds between strikes; false keeps only the strikes.

Default
true
glowColor?string

The colour of the light in the clouds and of the bolts' halo, any CSS colour.

Default
"oklch(0.8 0.1 280)"
intensity?"subtle" | "medium" | "strong"

How bright the flashes get.

Type
"subtle" | "medium" | "strong"
Default
"medium"
rain?boolean

Faint rain falling under the clouds.

Default
true
speed?number

How fast the storm moves: 1 is a strike or a flash about every 3 s and clouds drifting slowly. It's capped at 1.5, so it never flashes more than twice a second.

Default
1
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

CSS variableType
--lightning-colorstring

The bolts' core (a near-white violet).

--lightning-glowstring

The light in the clouds and the bolts' halo (a pale violet).

--lightning-speedstring

How fast the storm moves, a multiplier (1), at most 1.5.

--lightning-strengthstring

How bright the flashes get, a multiplier (1).

All 100 backgrounds