Spinner
Indeterminate loading indicators in three styles with accessible status text.
AI prompt
Build three spinner variants side by side, each labelled: a ring (40px, 3px border with a coloured top segment rotating 800ms linear infinite), three bouncing dots (10px circles bouncing 8px with 1000ms duration and 150ms stagger) and a pulsing circle (scale 0.6 to 1 with fading opacity over 1200ms). Wrap each in an element with role="status" and a visually hidden "Loading" text. Add a "Simulate request" button that shows a spinner after a 200ms delay (so very fast responses never flash one), keeps it for 1.5 seconds, then replaces it with the text "Done". Under prefers-reduced-motion replace all movement with a static visible "Loading…" caption.About this pattern
Definition
A small animated shape that tells the user a process is running when the duration is unknown. This page shows three versions: a rotating ring, bouncing dots and a pulsing circle.
Purpose & UX principles
- Use only for short, indeterminate waits (about 1 to 10 seconds). Longer waits need a progress indicator or an explanation.
- Always pair it with text, either visible ("Loading messages…") or hidden for screen readers.
- Delay showing it by about 200ms; spinners that flash for a moment feel slower than none.
Interaction states
- Idle (hidden), delayed, visible with
role="status", removed on completion. - Use
aria-live="polite"text so assistive technology announces start and finish.
Motion specification
- Ring: 800ms linear rotation.
- Dots: 1000ms bounce, 150ms stagger.
- Pulse: 1200ms scale and fade.
- Reduced motion: replace movement with a static "Loading…" label.
Responsive behaviour
- Size scales with the surrounding control: 16px inside buttons, 24px inline, 40px for sections.
- Centre in the area that is loading and keep that area's size stable.
Code
<div class="row">
<figure><div class="ring" role="status"><span class="sr">Loading</span></div><figcaption>Ring</figcaption></figure>
<figure><div class="dots" role="status"><i></i><i></i><i></i><span class="sr">Loading</span></div><figcaption>Dots</figcaption></figure>
<figure><div class="pulse" role="status"><span class="sr">Loading</span></div><figcaption>Pulse</figcaption></figure>
</div>
<div class="sim"><button id="go">Simulate request</button><p id="out" role="status" 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}
.row{display:flex;gap:36px;justify-content:center}
figure{display:grid;gap:12px;justify-items:center}figcaption{color:var(--muted);font-size:12px;letter-spacing:.1em;text-transform:uppercase}
.ring{width:40px;height:40px;border-radius:50%;border:3px solid var(--surface-2);border-top-color:var(--accent);animation:r .8s linear infinite}
.dots{display:flex;gap:6px;height:40px;align-items:center}.dots i{width:10px;height:10px;border-radius:50%;background:var(--accent);animation:b 1s ease-in-out infinite}
.dots i:nth-child(2){animation-delay:.15s}.dots i:nth-child(3){animation-delay:.3s}
.pulse{width:40px;height:40px;border-radius:50%;background:var(--accent);animation:p 1.2s ease-in-out infinite}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}
.sim{margin-top:28px;display:grid;gap:12px;justify-items:center}
.sim button{height:40px;padding:0 18px;border-radius:10px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer}
.sim button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sim p{min-height:28px;color:var(--muted);display:flex;align-items:center;gap:10px}
.mini{width:18px;height:18px;border-radius:50%;border:2px solid var(--surface-2);border-top-color:var(--accent);animation:r .8s linear infinite}
@keyframes r{to{transform:rotate(360deg)}}
@keyframes b{50%{transform:translateY(-8px)}}
@keyframes p{0%,100%{transform:scale(.6);opacity:.4}50%{transform:scale(1);opacity:1}}
@media (prefers-reduced-motion:reduce){.ring,.dots i,.pulse,.mini{animation:none}.ring::after,.dots::after,.pulse::after{content:"Loading…";color:var(--muted);font-size:12px;position:absolute;margin-top:46px}}const go=document.getElementById('go'),out=document.getElementById('out');
go.onclick=()=>{out.textContent='';let shown=false;
const t=setTimeout(()=>{shown=true;out.innerHTML='<span class="mini" aria-hidden="true"></span>Loading…';},200);
setTimeout(()=>{clearTimeout(t);out.textContent='Done';},1500);};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>Spinner — 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}}
.row{display:flex;gap:36px;justify-content:center}
figure{display:grid;gap:12px;justify-items:center}figcaption{color:var(--muted);font-size:12px;letter-spacing:.1em;text-transform:uppercase}
.ring{width:40px;height:40px;border-radius:50%;border:3px solid var(--surface-2);border-top-color:var(--accent);animation:r .8s linear infinite}
.dots{display:flex;gap:6px;height:40px;align-items:center}.dots i{width:10px;height:10px;border-radius:50%;background:var(--accent);animation:b 1s ease-in-out infinite}
.dots i:nth-child(2){animation-delay:.15s}.dots i:nth-child(3){animation-delay:.3s}
.pulse{width:40px;height:40px;border-radius:50%;background:var(--accent);animation:p 1.2s ease-in-out infinite}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}
.sim{margin-top:28px;display:grid;gap:12px;justify-items:center}
.sim button{height:40px;padding:0 18px;border-radius:10px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer}
.sim button:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sim p{min-height:28px;color:var(--muted);display:flex;align-items:center;gap:10px}
.mini{width:18px;height:18px;border-radius:50%;border:2px solid var(--surface-2);border-top-color:var(--accent);animation:r .8s linear infinite}
@keyframes r{to{transform:rotate(360deg)}}
@keyframes b{50%{transform:translateY(-8px)}}
@keyframes p{0%,100%{transform:scale(.6);opacity:.4}50%{transform:scale(1);opacity:1}}
@media (prefers-reduced-motion:reduce){.ring,.dots i,.pulse,.mini{animation:none}.ring::after,.dots::after,.pulse::after{content:"Loading…";color:var(--muted);font-size:12px;position:absolute;margin-top:46px}}
</style></head>
<body><div class="stage">
<div class="row">
<figure><div class="ring" role="status"><span class="sr">Loading</span></div><figcaption>Ring</figcaption></figure>
<figure><div class="dots" role="status"><i></i><i></i><i></i><span class="sr">Loading</span></div><figcaption>Dots</figcaption></figure>
<figure><div class="pulse" role="status"><span class="sr">Loading</span></div><figcaption>Pulse</figcaption></figure>
</div>
<div class="sim"><button id="go">Simulate request</button><p id="out" role="status" aria-live="polite"></p></div>
</div>
<script>
const go=document.getElementById('go'),out=document.getElementById('out');
go.onclick=()=>{out.textContent='';let shown=false;
const t=setTimeout(()=>{shown=true;out.innerHTML='<span class="mini" aria-hidden="true"></span>Loading…';},200);
setTimeout(()=>{clearTimeout(t);out.textContent='Done';},1500);};
</script>
</body></html>