Animated Checkmark Button
A submit button that shrinks into a spinner and finishes by drawing a checkmark.
AI prompt
Create a "Send message" button, 44px tall and 160px wide, with a dark fill and white label. On click enter the working stage: set aria-busy, collapse the width to 44px over 260ms cubic-bezier(.2,.7,.2,1) while the label fades out and a 18px CSS spinner (700ms linear) fades in. After 1 second enter the success stage: replace the spinner with an SVG check mark (path length 24) that draws using stroke-dashoffset from 24 to 0 over 360ms ease-out, and change the fill to a green (#1a7f4b). After 1.6 seconds return to the idle state, expanding the width back. Ignore clicks while not idle. Announce "Message sent" in a polite live region. Show a 2px focus-visible ring. Under prefers-reduced-motion remove width and draw animations and switch stages instantly.About this pattern
Definition
A button that moves through three visible stages: idle label, working spinner and success check. The final check is drawn like a pen stroke using an SVG path.
Purpose & UX principles
- Confirms that the action was received and completed, without a separate message.
- Locks the button while working so it cannot be submitted twice.
- The result is also announced in a live region so it is not purely visual.
Interaction states
- Idle, working (
aria-busy), success, back to idle after 1.6 seconds, focus-visible.
Motion specification
- Width collapse: 260ms cubic-bezier(.2,.7,.2,1).
- Check draw: stroke-dashoffset from 24 to 0 over 360ms ease-out.
- Reduced motion: stages change instantly and the check appears without drawing.
Responsive behaviour
- Fixed 44px height; the button shrinks to a 44px circle while working and grows back.
- Works the same with touch and keyboard.
Code
<div class="wrap">
<button class="b" id="b"><span class="l">Send message</span><span class="sp" aria-hidden="true"></span><svg class="ck" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.500l4.500 4.500L19 7.500"/></svg></button>
<p class="live" id="live" aria-live="polite"></p>
</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}
.wrap{display:grid;justify-items:center;gap:10px}
.b{position:relative;width:160px;height:44px;border-radius:22px;border:0;background:var(--accent);color:var(--accent-ink);font:inherit;font-size:14px;font-weight:600;cursor:pointer;overflow:hidden;transition:width .26s cubic-bezier(.2,.7,.2,1),background .2s}
.b:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.l{transition:opacity .15s}
.sp,.ck{position:absolute;left:50%;top:50%;margin:-9px 0 0 -9px;width:18px;height:18px;opacity:0}
.sp{border-radius:50%;border:2px solid rgba(255,255,255,.3);border-top-color:#fff}
.ck{fill:none;stroke:#fff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:24;stroke-dashoffset:24}
.b.work{width:44px}.b.work .l{opacity:0}.b.work .sp{opacity:1;animation:r .7s linear infinite}
.b.ok{width:44px;background:#1a7f4b}.b.ok .l{opacity:0}.b.ok .ck{opacity:1;stroke-dashoffset:0;transition:stroke-dashoffset .36s ease-out}
@keyframes r{to{transform:rotate(360deg)}}
.live{font-size:12px;color:var(--muted);min-height:18px}
@media (prefers-reduced-motion:reduce){.b,.l,.b.ok .ck{transition:none}.b.work .sp{animation:none}}const b=document.getElementById('b'),live=document.getElementById('live');let busy=false;
b.addEventListener('click',()=>{if(busy)return;busy=true;b.classList.add('work');b.setAttribute('aria-busy','true');live.textContent='Sending…';
setTimeout(()=>{b.classList.remove('work');b.classList.add('ok');b.removeAttribute('aria-busy');live.textContent='Message sent';
setTimeout(()=>{b.classList.remove('ok');live.textContent='';busy=false;},1600);},1000);});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>Animated Checkmark Button — 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}}
.wrap{display:grid;justify-items:center;gap:10px}
.b{position:relative;width:160px;height:44px;border-radius:22px;border:0;background:var(--accent);color:var(--accent-ink);font:inherit;font-size:14px;font-weight:600;cursor:pointer;overflow:hidden;transition:width .26s cubic-bezier(.2,.7,.2,1),background .2s}
.b:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.l{transition:opacity .15s}
.sp,.ck{position:absolute;left:50%;top:50%;margin:-9px 0 0 -9px;width:18px;height:18px;opacity:0}
.sp{border-radius:50%;border:2px solid rgba(255,255,255,.3);border-top-color:#fff}
.ck{fill:none;stroke:#fff;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:24;stroke-dashoffset:24}
.b.work{width:44px}.b.work .l{opacity:0}.b.work .sp{opacity:1;animation:r .7s linear infinite}
.b.ok{width:44px;background:#1a7f4b}.b.ok .l{opacity:0}.b.ok .ck{opacity:1;stroke-dashoffset:0;transition:stroke-dashoffset .36s ease-out}
@keyframes r{to{transform:rotate(360deg)}}
.live{font-size:12px;color:var(--muted);min-height:18px}
@media (prefers-reduced-motion:reduce){.b,.l,.b.ok .ck{transition:none}.b.work .sp{animation:none}}
</style></head>
<body><div class="stage">
<div class="wrap">
<button class="b" id="b"><span class="l">Send message</span><span class="sp" aria-hidden="true"></span><svg class="ck" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.500l4.500 4.500L19 7.500"/></svg></button>
<p class="live" id="live" aria-live="polite"></p>
</div>
</div>
<script>
const b=document.getElementById('b'),live=document.getElementById('live');let busy=false;
b.addEventListener('click',()=>{if(busy)return;busy=true;b.classList.add('work');b.setAttribute('aria-busy','true');live.textContent='Sending…';
setTimeout(()=>{b.classList.remove('work');b.classList.add('ok');b.removeAttribute('aria-busy');live.textContent='Message sent';
setTimeout(()=>{b.classList.remove('ok');live.textContent='';busy=false;},1600);},1000);});
</script>
</body></html>