Join our Discord Community

React Fireworks Background

Explosive celebrations that respond to your clicks like the Fourth of July went digital. Build interactive React backgrounds with canvas physics, particle explosions, TypeScript support, and click-to-launch fireworks for Next.js applications with shadcn/ui.

Trying to implement particle explosions?

Join our Discord community for help from other developers.


Who doesn't love fireworks? This React component brings that explosive celebration to your web app. Click anywhere and watch particles arc through the air, explode into brilliant bursts, then fade away with realistic physics. It's like having a fireworks show in your browser, minus the noise complaints.

Interactive celebration effects

Click anywhere to launch fireworks with realistic physics and gravity:

Loading component...

Built for React applications with TypeScript and Next.js. The animation runs on HTML5 Canvas with requestAnimationFrame, so you get smooth 60fps explosions. Customize colors, speeds, sizes, and population—from subtle sparkles to full-blown New Year's Eve mayhem.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/fireworks-background.json
npx shadcn@latest add https://www.shadcn.io/registry/fireworks-background.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/fireworks-background.json
bunx shadcn@latest add https://www.shadcn.io/registry/fireworks-background.json

Usage

import { FireworksBackground } from "@/components/ui/fireworks-background";

export default function Celebration() {
  return (
    <div className="relative h-screen">
      <FireworksBackground
        population={3}
        color={["#ff0000", "#00ff00", "#0000ff", "#ffff00"]}
        fireworkSpeed={{min: 4, max: 8}}
        particleSize={{min: 2, max: 6}}
      />
      <div className="relative z-10 text-white p-8">
        <h1>Click anywhere to celebrate!</h1>
      </div>
    </div>
  );
}

Why most firework animations look fake

Most developers use pre-made GIFs or simple CSS animations. Static, repetitive, no physics. Some try particle libraries but end up with floating dots that ignore gravity. Real fireworks have weight—they arc up, explode at peak height, then fall down with particle trails.

This React component simulates actual physics. Fireworks launch with initial velocity, slow down due to gravity, explode at peak trajectory, then particles scatter with momentum and fade with realistic decay. Click anywhere and the firework aims for that spot. Canvas rendering keeps it smooth even with hundreds of particles exploding simultaneously.

Examples

High Population

More frequent launches for constant celebration:

Loading component...

Variable Sizes and Speeds

Dynamic range parameters for organic, unpredictable effects:

Loading component...

Fixed Parameters

Consistent sizing for uniform, controlled patterns:

Loading component...

Features

  • Click-to-launch interactivity aiming fireworks toward cursor position
  • Realistic physics simulation with gravity, momentum, and particle decay
  • Configurable parameters for population, colors, speeds, and sizes
  • Range or fixed values supporting both random and consistent effects
  • Canvas-based rendering with smooth 60fps animations
  • TypeScript definitions for all configuration options
  • Automatic cleanup preventing memory leaks on unmount
  • shadcn/ui compatible with responsive container sizing

API Reference

FireworksBackground

Main component for the fireworks animation canvas.

PropTypeDefaultDescription
populationnumber1Launch frequency (higher = more fireworks)
colorstring | string[]randColor()Single color or array for fireworks
fireworkSpeed{min: number, max: number} | number{min: 4, max: 8}Launch velocity range or fixed speed
fireworkSize{min: number, max: number} | number{min: 2, max: 5}Trail thickness range or fixed size
particleSpeed{min: number, max: number} | number{min: 2, max: 7}Explosion particle speed range
particleSize{min: number, max: number} | number{min: 1, max: 5}Explosion particle size range
canvasPropsComponentProps<'canvas'>-Additional canvas element props

Parameter Types

// Range for randomized values
type Range = { min: number; max: number };

// Fixed value for consistent effects
type Fixed = number;

// Color options
type Color = string | string[];

Common gotchas

Canvas sizing issues: The canvas auto-resizes to its container. If fireworks aren't showing, check that the parent has explicit dimensions like h-screen.

Performance with high population: Each firework spawns dozens of particles. Population above 5 might lag on weak devices. Test on target hardware.

Click detection problems: Click handlers are on the canvas element. Z-index conflicts with overlays can block interaction. Ensure the canvas is clickable.

Memory leaks with rapid mounting: The component cleans up requestAnimationFrame automatically, but rapidly changing props might cause issues. Use stable keys when possible.

Colors not showing: Color arrays need valid CSS color strings. Hex, RGB, and named colors all work. Invalid colors fall back to random generation.

You might also like

Explore other celebratory background components for React applications:

Questions developers actually ask