@tsparticles/confetti
v4.0.5
Published
Easily create highly customizable particle animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
Keywords
Readme
tsParticles Confetti Bundle
tsParticles confetti bundle to create confetti effects with a single API.
Included Packages
- @tsparticles/basic (and all its dependencies)
- @tsparticles/engine
- @tsparticles/plugin-emitters
- @tsparticles/plugin-motion
- @tsparticles/shape-cards
- @tsparticles/shape-emoji
- @tsparticles/shape-heart
- @tsparticles/shape-image
- @tsparticles/shape-polygon
- @tsparticles/shape-square
- @tsparticles/shape-star
- @tsparticles/updater-life
- @tsparticles/updater-roll
- @tsparticles/updater-rotate
- @tsparticles/updater-tilt
- @tsparticles/updater-wobble
Dependency Graph
flowchart TD
subgraph b [Bundle]
bc[tsparticles/confetti]
bb[tsparticles/basic]
end
subgraph c [Core]
ce[tsparticles/engine]
end
subgraph p [Plugins]
pe[tsparticles/plugin-emitters]
pm[tsparticles/plugin-motion]
end
subgraph s [Shapes]
sca[tsparticles/shape-cards]
se[tsparticles/shape-emoji]
sh[tsparticles/shape-heart]
si[tsparticles/shape-image]
sp[tsparticles/shape-polygon]
ss[tsparticles/shape-square]
sst[tsparticles/shape-star]
end
subgraph u [Updaters]
ul[tsparticles/updater-life]
ur[tsparticles/updater-roll]
uro[tsparticles/updater-rotate]
ut[tsparticles/updater-tilt]
uw[tsparticles/updater-wobble]
end
bc --> bb
bc --> ce
bc --> p
bc --> s
bc --> uExposed API
The package API is centered on confetti.
import { confetti } from "@tsparticles/confetti";
// Main API
await confetti(options);
await confetti("canvas-id", options);
// Extra helpers
await confetti.init();
const fireOnCanvas = await confetti.create(canvas, defaultOptions);
await fireOnCanvas(options);
console.log(confetti.version);@tsparticles/confetti does not expose tsParticles from its main entrypoint.
If you need direct engine APIs, import them from @tsparticles/engine.
Installation
pnpm add @tsparticles/confettiHow to use it
ESM / TypeScript
import { confetti } from "@tsparticles/confetti";
await confetti({
count: 80,
spread: 60,
position: { x: 50, y: 50 },
colors: ["#ffffff", "#ff0000"],
});With explicit canvas id:
import { confetti } from "@tsparticles/confetti";
await confetti("tsparticles", {
count: 50,
angle: 90,
spread: 45,
});Custom canvas via confetti.create
import { confetti } from "@tsparticles/confetti";
const canvas = document.getElementById("my-canvas") as HTMLCanvasElement;
const localConfetti = await confetti.create(canvas, { count: 30 });
await localConfetti({ spread: 70 });CDN / Vanilla JS / jQuery
The CDN/Vanilla JS version has two files:
- One is a bundle file with all the scripts included in a single file
- One includes only the
confettiAPI, where dependencies must be loaded manually
After loading the bundle, confetti is available on globalThis.
Bundle
Use the bundle when you want a single script with all required dependencies.
Not Bundle
This installation requires more work since all dependencies must be included in the page. Some lines above are all specified in the Included Packages section.
Usage
confetti({ count: 60 });(async () => {
await confetti({ count: 60, spread: 55 });
})();confetti("tsparticles", {
count: 50,
position: {
x: 50,
y: 50,
},
});Options
The confetti API accepts:
confetti(options)confetti(id, options)
Main options:
countInteger (default: 50)angleNumber (default: 90)spreadNumber (default: 45)startVelocityNumber (default: 45)decayNumber (default: 0.9)flatBoolean (default: false)gravityNumber (default: 1)driftNumber (default: 0)ticksNumber (default: 200)positionObject (x/y, default 50/50)colorsArray<String>shapesArray<String>shapeOptionsRecord<string, unknown>scalarNumber (default: 1)zIndexInteger (default: 100)disableForReducedMotionBoolean (default: true)
Deprecated aliases still accepted:
particleCount(usecount)origin(useposition)
Common pitfalls
- Calling
confettibefore scripts are loaded in CDN usage - Assuming
tsParticlesis exported by@tsparticles/confettimain entrypoint - Passing no first argument in TypeScript (use
confetti(options)orconfetti(id, options))
Related docs
- All packages catalog: https://github.com/tsparticles/tsparticles
- Main docs: https://particles.js.org/docs/

