Aurora Background
An animated aurora background for React: soft, blurred bands of color that drift and sway like the northern lights. Built with Motion and Tailwind CSS, it animates only GPU-friendly transforms, pauses off-screen and holds a still frame for reduced motion.
- Background
- Gradient
- GPU transforms
- Pauses off-screen
- Reduced-motion safe
Deploy previews for every branch
Every push gets its own URL, so reviewers can try changes before they merge.
import { Button } from "@/components/ui/button";
import { AuroraBackground } from "@/components/dusk/backgrounds/aurora-background";
export default function AuroraBackgroundDemo() {
return (
<div className="relative flex h-80 w-full items-center justify-center overflow-hidden rounded-xl border border-white/10 bg-background">
<AuroraBackground />
<div className="relative px-6 text-center">
<h3 className="text-3xl font-semibold tracking-tight text-white sm:text-4xl">Deploy previews for every branch</h3>
<p className="mx-auto mt-2 max-w-sm text-sm leading-relaxed text-white/60">
Every push gets its own URL, so reviewers can try changes before they merge.
</p>
<Button className="mt-5">Get started</Button>
</div>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/aurora-background.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/backgrounds/aurora-background.tsx.aurora-background.tsx "use client"; import * as React from "react"; import { animate, useReducedMotion, type AnimationPlaybackControls } from "motion/react"; import { cn } from "@/lib/utils"; export interface AuroraBackgroundProps extends React.ComponentProps<"div"> { /** Colors of the light bands, any CSS color. One band is drawn per color (up to 6). */ colors?: string[]; /** Overall brightness, from 0 (off) to 1 (vivid). */ intensity?: number; /** Speed multiplier. `1` drifts slowly; lower is calmer. */ speed?: number; /** Softness of the bands in px. */ blur?: number; /** Fade the aurora out toward the bottom and sides. */ fade?: boolean; } const DEFAULT_COLORS = ["var(--color-primary)", "#38bdf8", "#6366f1"]; /** * Hand-placed band layouts, in percent of the container. Bands sit near the * top and overlap, so any palette blends into a single sky. */ const LAYOUTS = [ { left: -15, top: -30, width: 75, height: 70, rotate: -14, drift: [8, 5, -4] }, { left: 35, top: -35, width: 80, height: 65, rotate: 10, drift: [-7, 6, 4] }, { left: 5, top: -5, width: 65, height: 50, rotate: -6, drift: [6, -5, 3] }, { left: 45, top: -10, width: 70, height: 55, rotate: 16, drift: [-5, 7, -3] }, { left: 15, top: -40, width: 85, height: 60, rotate: -20, drift: [4, 8, -5] }, { left: -5, top: 5, width: 60, height: 45, rotate: 4, drift: [-6, -4, 4] }, ]; /** * A soft, slowly shifting aurora: layered, blurred gradient bands that drift, * stretch and sway like northern lights. Fills its nearest positioned parent. * * Only transforms are animated, so every band stays on its own GPU layer. * Animation pauses off-screen and in hidden tabs, and reduced motion keeps a * still frame of the same sky. */ export function AuroraBackground({ colors = DEFAULT_COLORS, intensity = 0.35, speed = 1, blur = 64, fade = true, className, style, ...props }: AuroraBackgroundProps) { const reduceMotion = useReducedMotion(); const rootRef = React.useRef<HTMLDivElement>(null); const bandRefs = React.useRef<(HTMLDivElement | null)[]>([]); const palette = (colors.length ? colors : DEFAULT_COLORS).slice(0, LAYOUTS.length); const bandCount = palette.length; React.useEffect(() => { const root = rootRef.current; if (!root || reduceMotion) return; const rate = Math.max(speed, 0.05); const controls: AnimationPlaybackControls[] = []; for (let i = 0; i < bandCount; i++) { const el = bandRefs.current[i]; if (!el) continue; const { rotate, drift } = LAYOUTS[i]; const [dx, dy, dr] = drift; controls.push( animate( el, { x: ["0%", `${dx}%`, `${-dx * 0.6}%`, "0%"], y: ["0%", `${dy}%`, `${-dy * 0.5}%`, "0%"], rotate: [rotate, rotate + dr, rotate - dr * 0.5, rotate], scaleX: [1, 1.12, 0.95, 1], scaleY: [1, 0.92, 1.06, 1], }, { duration: (24 + i * 6) / rate, ease: "easeInOut", repeat: Infinity } ) ); } let inView = true; const sync = () => { const play = inView && !document.hidden; for (const c of controls) { if (play) c.play(); else c.pause(); } }; const observer = new IntersectionObserver(([entry]) => { inView = entry.isIntersecting; sync(); }); observer.observe(root); document.addEventListener("visibilitychange", sync); return () => { for (const c of controls) c.stop(); observer.disconnect(); document.removeEventListener("visibilitychange", sync); }; }, [bandCount, speed, reduceMotion]); return ( <div ref={rootRef} aria-hidden data-slot="aurora-background" className={cn( "pointer-events-none absolute inset-0 isolate overflow-hidden", fade && "[mask-image:radial-gradient(ellipse_90%_80%_at_50%_0%,#000_35%,transparent_100%)]", className )} style={style} {...props} > <div className="absolute inset-0" style={{ opacity: Math.min(Math.max(intensity, 0), 1) }}> {palette.map((color, i) => { const { left, top, width, height, rotate } = LAYOUTS[i]; return ( <div key={i} ref={(el) => { bandRefs.current[i] = el; }} className="absolute rounded-[50%] mix-blend-screen will-change-transform" style={{ left: `${left}%`, top: `${top}%`, width: `${width}%`, height: `${height}%`, transform: `rotate(${rotate}deg)`, background: `radial-gradient(50% 50% at 50% 50%, ${color} 0%, color-mix(in oklab, ${color} 35%, transparent) 40%, transparent 100%)`, filter: blur > 0 ? `blur(${blur}px)` : undefined, }} /> ); })} </div> </div> ); }
The aurora fills its nearest positioned parent, so give the parent relative and overflow-hidden, and put your content after it with relative so it sits on top.
Usage
import { AuroraBackground } from "@/components/dusk/backgrounds/aurora-background"
export function Hero() {
return (
<section className="relative overflow-hidden">
<AuroraBackground />
<div className="relative">{/* your content */}</div>
</section>
)
}Examples
Custom palettes
Pass any CSS colors to colors; each one becomes a band, up to six. Colors blend with a screen blend mode, so overlapping bands glow brighter.
Sunset
3 colors
Glacier
4 colors
import { AuroraBackground } from "@/components/dusk/backgrounds/aurora-background";
const palettes = [
{ label: "Sunset", colors: ["#f472b6", "#fb923c", "#a78bfa"] },
{ label: "Glacier", colors: ["#38bdf8", "#e0f2fe", "#6366f1", "#22d3ee"] },
];
export default function AuroraBackgroundColors() {
return (
<div className="grid w-full gap-4 sm:grid-cols-2">
{palettes.map((palette) => (
<div
key={palette.label}
className="relative flex h-56 items-end overflow-hidden rounded-xl border border-white/10 bg-background p-4"
>
<AuroraBackground colors={palette.colors} />
<div className="relative">
<p className="text-sm font-medium text-white">{palette.label}</p>
<p className="text-xs text-white/60">{palette.colors.length} colors</p>
</div>
</div>
))}
</div>
);
}Subtle backdrop
Lower intensity and speed and raise blur for a quiet backdrop behind forms and dialogs.
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { AuroraBackground } from "@/components/dusk/backgrounds/aurora-background";
export default function AuroraBackgroundSubtle() {
return (
<div className="relative flex h-80 w-full items-center justify-center overflow-hidden rounded-xl border border-white/10 bg-background p-6">
<AuroraBackground intensity={0.2} speed={0.5} blur={80} />
<form className="relative w-full max-w-sm space-y-3 rounded-xl border border-white/10 bg-card/80 p-5 backdrop-blur-md">
<h3 className="text-lg font-semibold text-white">Join the waitlist</h3>
<p className="text-sm text-white/60">We will email you once when your invite is ready.</p>
<div className="flex gap-2">
<Input type="email" placeholder="you@example.com" aria-label="Email" />
<Button type="button">Notify me</Button>
</div>
</form>
</div>
);
}API Reference
Any other div prop is passed to the root. Band positions are fixed per index, so the same palette always draws the same sky on the server and the client.
| Prop | Type | Default | Description |
|---|---|---|---|
| colors | string[] | ["var(--color-primary)", "#38bdf8", "#6366f1"] | Band colors, any CSS color. One band per color, up to six. |
| intensity | number | 0.35 | Overall brightness, from 0 to 1. |
| speed | number | 1 | Speed multiplier for the drift. |
| blur | number | 64 | Softness of the bands in px. 0 turns the blur filter off. |
| fade | boolean | true | Fade the aurora out toward the bottom and sides. |
| className | string | — | Merged onto the absolutely positioned root. |
Accessibility
- The aurora is decorative: it is
aria-hiddenandpointer-events-none, so it never reaches screen readers or blocks clicks. - With prefers-reduced-motion the bands stay still in their resting positions; the colors remain.
- Animation pauses while the aurora is off-screen or the tab is hidden, saving battery.
- Bright palettes can reduce contrast; keep text on a card or lower the intensity.