Fireworks Background

A background component that displays a fireworks animation.

<script setup lang="ts">
import FireworksBackground from '@/components/animate-ui/backgrounds/fireworks/FireworksBackground.vue'
import { useDark } from '@/lib/use-dark'

withDefaults(defineProps<{ population?: number | string }>(), { population: 1 })

const dark = useDark()
</script>

<template>
  <FireworksBackground
    class="absolute inset-0"
    :color="dark ? 'white' : 'black'"
    :population="Number(population)"
  />
</template>

Installation

npx shadcn-vue@latest add https://animate-ui.com/r/vue/backgrounds-fireworks.json
pnpm dlx shadcn-vue@latest add https://animate-ui.com/r/vue/backgrounds-fireworks.json
yarn dlx shadcn-vue@latest add https://animate-ui.com/r/vue/backgrounds-fireworks.json
bun x shadcn-vue@latest add https://animate-ui.com/r/vue/backgrounds-fireworks.json

Usage

<script setup lang="ts">
import FireworksBackground from '@/components/animate-ui/backgrounds/fireworks/FireworksBackground.vue';
</script>

<template>
  <section class="relative h-[480px] overflow-hidden">
    <FireworksBackground class="absolute inset-0" />
  </section>
</template>

Examples

Fireworks Circle

<script setup lang="ts">
import FireworksBackground from '@/components/animate-ui/backgrounds/fireworks/FireworksBackground.vue'
import { useDark } from '@/lib/use-dark'

withDefaults(
  defineProps<{
    population?: number | string
    fireworkSize?: number | string
    fireworkSpeed?: number | string
    particleSize?: number | string
    particleSpeed?: number | string
  }>(),
  { population: 1, fireworkSize: 7, fireworkSpeed: 7, particleSize: 7, particleSpeed: 7 },
)

const dark = useDark()
</script>

<template>
  <FireworksBackground
    class="absolute inset-0"
    :color="dark ? 'white' : 'black'"
    :population="Number(population)"
    :firework-size="Number(fireworkSize)"
    :firework-speed="Number(fireworkSpeed)"
    :particle-size="Number(particleSize)"
    :particle-speed="Number(particleSpeed)"
  />
</template>

Animation

  • Rockets launch from the bottom edge every 300 to 800ms (divided by population), trail upwards and burst into 50 to 150 particles that slow down, fall and fade.
  • A click launches a rocket towards the pointer.
  • The show takes place in a space as wide as the window, with the container's aspect ratio, scaled down to the container: in a container narrower than the window, rockets and particles are smaller and slower. The canvas is drawn at the device pixel ratio.
  • The simulation advances one step per displayed frame, so it runs faster on 120Hz screens.
  • It pauses off screen and while the tab is hidden: nothing launches and the last frame stays.
  • Under reduced motion, it shows a still frame of three bursts and clicks do nothing.

API Reference

FireworksBackground

PropTypeDefault
population?
number1
color?
string | string[]a random hue per rocket
firework-speed?
number | { min: number; max: number }{ min: 4, max: 8 }
firework-size?
number | { min: number; max: number }{ min: 2, max: 5 }
particle-speed?
number | { min: number; max: number }{ min: 2, max: 7 }
particle-size?
number | { min: number; max: number }{ min: 1, max: 5 }
canvas-props?
CanvasHTMLAttributes-
...attrs?
HTMLAttributes-

Credits

Built by Skyleen. The source code is available on GitHub.

Last updated: 10/23/2026