The idea
A big yellow "party" button. Every click fires a burst of confetti and the counter goes up. Mash it and the bursts stack. That's it, and that's the point.
Why
Confetti libraries tend to bring a canvas, a render loop, and a physics simulation with them, all for a moment that lasts under a second. I wanted to know how small a convincing burst could be when it's built from the motion system the site already ships.
The answer turned out to be: very small.
Approach
- Fourteen divs per burst. Each particle is an absolutely positioned span, alternating circles and squares across the five accent colors.
- Even spread, a little chaos. Particles are fanned out evenly around a circle, then each gets a random wobble in its angle, distance, and spin. The even spread keeps the burst looking full, and the randomness stops it looking like a firework diagram.
- Biased upward. Every particle's target is nudged 40px up, so the burst feels like it's thrown, not dropped.
- One spring does the work. Particles fly out on a gentle spring (stiffness 120, damping 14) while shrinking to nothing. After 900ms the burst is removed from state.
Decisions & trade-offs
- No canvas. DOM particles cap out at a few hundred before they get expensive, but a single click only makes fourteen. For a button, that's the right side of the trade.
- Transform and opacity only. Every property that moves is GPU-friendly, so the burst never triggers layout.
- Hidden from assistive tech. The particle layer is marked
aria-hidden. Confetti is decoration. The counter text carries the actual feedback.
What I'd try next
- Gravity. Right now particles shrink away instead of falling, and a little arc would sell it.
- Turning
useConfettiinto a shared hook so real moments on the site, like a sent contact form, can celebrate too.