canvas-confetti
~8kb gzippedOne-shot confetti bursts for celebrations and success states.
See It in Action
Each demo fires confetti on a user action. No ambient background -- the particles start, fall, and clean themselves up.
Click the button to fire a confetti burst from the cursor. The simplest canvas-confetti pattern: call confetti() with an origin.
What is canvas-confetti?
canvas-confetti is a tiny (~8kb gzipped) library that throws confetti on the screen. Call confetti() and 50 paper pieces burst from the middle of the page, fall with real physics, and clean themselves up -- no canvas setup, no config required.
The full API lets you aim bursts from any coordinate, change the angle, spread, particle count, velocity, gravity, drift, colors, and shapes. At ~16.8M weekly npm downloads it is the default "something happy just happened" library for the web. Pair it with a success button, an onboarding milestone, or an Easter egg on your logo.
When to Use canvas-confetti
How canvas-confetti Compares
These solve different problems. tsParticles is for ambient, always-running background scenes (snow, constellations, ambient dust). canvas-confetti is for one-shot celebrations on specific user actions. Use both on the same site if you want -- they do not conflict.
You could fake confetti with a handful of @keyframes-animated DOM elements. It works but falls apart with 50+ pieces, varied shapes, and natural physics. canvas-confetti simulates gravity + drag + rotation per particle -- CSS cannot.
Get Started with canvas-confetti
npm install canvas-confetti
yarn add canvas-confetti
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
<button id="celebrate">Celebrate</button>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/confetti.browser.min.js"></script>
<script>
// Simplest use -- just call confetti(). Bursts from the center of the page.
document.getElementById("celebrate").addEventListener("click", function () {
confetti();
});
// Aim the burst. Origin is 0-1 on each axis (0.5, 0.5 = center).
// particleCount, spread, angle, startVelocity, colors, shapes are all options.
// confetti({
// particleCount: 120,
// spread: 70,
// origin: { y: 0.6 },
// colors: ["#4ecdc4", "#f39c12", "#e74c3c"]
// });
</script>