Success Confetti Burst
A button that bursts confetti when a task completes, with a calm checkmark for reduced motion.
AI prompt
Celebration illustration of a burst of colourful confetti exploding upward and outward from a round dark button with a white checkmark, small rectangles and circles in coral, yellow, teal and violet, frozen mid-air at different angles with a slight motion blur, a soft glow behind the button, clean off-white background, joyful and uncluttered. Variant: a calm static version with only a green checkmark badge and the text Done. Negative: clutter, photographic backgrounds, text errors, logos, noise. Reduced motion: static checkmark.About this pattern
Definition
Confetti marks a moment of achievement, such as finishing onboarding or completing a goal. Pieces fly outward from a point, spin, fall under gravity and fade. It should be rare, short and skippable, because overuse makes celebration meaningless.
Purpose & UX principles
- Use about 30 to 60 small pieces in a few brand colours.
- Launch them from the action that caused the success.
- Animate with the Web Animations API and remove the elements when done, in about 1.2 seconds.
- Pair with a clear message; the confetti is decoration, not the information.
Interaction states
- A Complete task button and a Replay.
Motion specification
- Pieces burst, spin and fall for 1.2 seconds, then are removed.
- Reduced motion: no particles; a checkmark and message appear instead.
Responsive behaviour
- Provide a non-motion alternative: a checkmark and a message.
- Do not fire it on every small action.
Code
<div class="bx"><div class="ar" id="ar"><button class="cb" id="cb" type="button">Complete task</button><p class="ms" id="ms" role="status"></p></div><button class="mini" id="rs" type="button">Reset</button></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.ar{position:relative;height:130px;border:1px solid var(--line);border-radius:12px;background:var(--surface);display:grid;place-items:center;align-content:center;gap:8px;overflow:hidden}.cb{height:42px;padding:0 22px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-weight:600;font-size:13.5px}.cb[disabled]{background:#2e9e4f;cursor:default}.ms{font-size:12.5px;color:#1a7f3c;font-weight:600;min-height:18px}.pc{position:absolute;left:50%;top:50%;width:8px;height:12px;pointer-events:none}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const ar=document.getElementById('ar'),cb=document.getElementById('cb'),ms=document.getElementById('ms'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches,CL=['#ff6b6b','#ffd23f','#2ec4b6','#8a5cff','#ff9f1c'];
function burst(){let s=11;const r=()=>(s=(s*1664525+1013904223)%4294967296)/4294967296,box=cb.getBoundingClientRect(),ab=ar.getBoundingClientRect(),cx=box.left-ab.left+box.width/2,cy=box.top-ab.top+box.height/2;
for(let i=0;i<44;i++){const e=document.createElement('i');e.className='pc';e.style.cssText='left:'+cx+'px;top:'+cy+'px;background:'+CL[i%5]+';border-radius:'+(i%3?'2px':'50%');ar.appendChild(e);const a=-Math.PI/2+(r()-.5)*2.6,v=60+r()*90,dx=Math.cos(a)*v,dy=Math.sin(a)*v;
e.animate([{transform:'translate(0,0) rotate(0)',opacity:1},{transform:'translate('+dx+'px,'+(dy)+'px) rotate('+(r()*360)+'deg)',opacity:1,offset:.45},{transform:'translate('+(dx*1.2)+'px,'+(dy+110)+'px) rotate('+(r()*720)+'deg)',opacity:0}],{duration:1100+r()*300,easing:'cubic-bezier(.2,.7,.3,1)'}).onfinish=()=>e.remove();}}
cb.addEventListener('click',()=>{cb.disabled=true;cb.textContent='\u2713 Done';ms.textContent='Task completed. Nice work!';if(!calm)burst();});
document.getElementById('rs').addEventListener('click',()=>{cb.disabled=false;cb.textContent='Complete task';ms.textContent='';ar.querySelectorAll('.pc').forEach(e=>e.remove());});One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Success Confetti Burst — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.ar{position:relative;height:130px;border:1px solid var(--line);border-radius:12px;background:var(--surface);display:grid;place-items:center;align-content:center;gap:8px;overflow:hidden}.cb{height:42px;padding:0 22px;border-radius:99px;background:var(--accent);color:var(--accent-ink);font-weight:600;font-size:13.5px}.cb[disabled]{background:#2e9e4f;cursor:default}.ms{font-size:12.5px;color:#1a7f3c;font-weight:600;min-height:18px}.pc{position:absolute;left:50%;top:50%;width:8px;height:12px;pointer-events:none}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="ar" id="ar"><button class="cb" id="cb" type="button">Complete task</button><p class="ms" id="ms" role="status"></p></div><button class="mini" id="rs" type="button">Reset</button></div>
</div>
<script>
const ar=document.getElementById('ar'),cb=document.getElementById('cb'),ms=document.getElementById('ms'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches,CL=['#ff6b6b','#ffd23f','#2ec4b6','#8a5cff','#ff9f1c'];
function burst(){let s=11;const r=()=>(s=(s*1664525+1013904223)%4294967296)/4294967296,box=cb.getBoundingClientRect(),ab=ar.getBoundingClientRect(),cx=box.left-ab.left+box.width/2,cy=box.top-ab.top+box.height/2;
for(let i=0;i<44;i++){const e=document.createElement('i');e.className='pc';e.style.cssText='left:'+cx+'px;top:'+cy+'px;background:'+CL[i%5]+';border-radius:'+(i%3?'2px':'50%');ar.appendChild(e);const a=-Math.PI/2+(r()-.5)*2.6,v=60+r()*90,dx=Math.cos(a)*v,dy=Math.sin(a)*v;
e.animate([{transform:'translate(0,0) rotate(0)',opacity:1},{transform:'translate('+dx+'px,'+(dy)+'px) rotate('+(r()*360)+'deg)',opacity:1,offset:.45},{transform:'translate('+(dx*1.2)+'px,'+(dy+110)+'px) rotate('+(r()*720)+'deg)',opacity:0}],{duration:1100+r()*300,easing:'cubic-bezier(.2,.7,.3,1)'}).onfinish=()=>e.remove();}}
cb.addEventListener('click',()=>{cb.disabled=true;cb.textContent='\u2713 Done';ms.textContent='Task completed. Nice work!';if(!calm)burst();});
document.getElementById('rs').addEventListener('click',()=>{cb.disabled=false;cb.textContent='Complete task';ms.textContent='';ar.querySelectorAll('.pc').forEach(e=>e.remove());});
</script>
</body></html>