176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loading Spinner — Animation Handbook</title>
<meta name="description" content="Six small shapes loop to show that something is loading. Best for short waits.">
<link rel="canonical" href="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/loading-spinner/">
<link rel="icon" type="image/png" sizes="96x96" href="../../../favicon.png">
<link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
<link rel="apple-touch-icon" href="../../../apple-touch-icon.png">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Animation Handbook">
<meta property="og:title" content="Loading Spinner — Animation Handbook">
<meta property="og:description" content="Six small shapes loop to show that something is loading. Best for short waits.">
<meta property="og:url" content="https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/loading-spinner/">
<meta property="og:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Loading Spinner — Animation Handbook">
<meta name="twitter:description" content="Six small shapes loop to show that something is loading. Best for short waits.">
<meta name="twitter:image" content="https://matinmonshizadeh.github.io/animation-handbook/og-image.png">
<script type="application/ld+json">{"@context": "https://schema.org", "@type": "TechArticle", "headline": "Loading Spinner", "name": "Loading Spinner", "description": "Six small shapes loop to show that something is loading. Best for short waits.", "url": "https://matinmonshizadeh.github.io/animation-handbook/animations/04-micro-interactions/loading-spinner/", "inLanguage": "en", "articleSection": "Micro-Interactions", "isPartOf": {"@type": "WebSite", "name": "Animation Handbook", "url": "https://matinmonshizadeh.github.io/animation-handbook/"}, "author": {"@type": "Person", "name": "matinmonshizadeh"}, "keywords": "web animation, CSS animation, Micro-Interactions, Loading Spinner"}</script>
<style>
:root{--ui-accent:#ff9d5c;--ui-bg:#111114;--ui-border:rgba(255,255,255,.09);--ui-muted:#8a8a92;--spd:800ms;--clr:#58a6ff;--sz:40px}
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
.stage{display:flex;align-items:center;justify-content:center;padding:16px;background:#0b0b0d}
.grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;width:100%;max-width:380px}
.spin-cell{display:flex;flex-direction:column;align-items:center;gap:10px;padding:12px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px}
.spin-label{font-size:11px;text-transform:uppercase;letter-spacing:1px;color:var(--ui-muted);text-align:center}
/* 1. Ring */
.sp-ring{width:var(--sz);height:var(--sz);border-radius:50%;border:3px solid rgba(255,255,255,.1);border-top-color:var(--clr);animation:spin var(--spd) linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
/* 2. Dots rotating */
.sp-dots{width:var(--sz);height:var(--sz);position:relative;animation:spin var(--spd) linear infinite}
.sp-dots span{position:absolute;width:calc(var(--sz)*0.2);height:calc(var(--sz)*0.2);border-radius:50%;background:var(--clr);top:50%;left:50%;transform-origin:0 0}
.sp-dots span:nth-child(1){transform:rotate(0deg) translateX(calc(var(--sz)*0.35));opacity:1}
.sp-dots span:nth-child(2){transform:rotate(60deg) translateX(calc(var(--sz)*0.35));opacity:.8}
.sp-dots span:nth-child(3){transform:rotate(120deg) translateX(calc(var(--sz)*0.35));opacity:.6}
.sp-dots span:nth-child(4){transform:rotate(180deg) translateX(calc(var(--sz)*0.35));opacity:.4}
.sp-dots span:nth-child(5){transform:rotate(240deg) translateX(calc(var(--sz)*0.35));opacity:.25}
.sp-dots span:nth-child(6){transform:rotate(300deg) translateX(calc(var(--sz)*0.35));opacity:.1}
/* 3. SVG arc */
.sp-arc{width:var(--sz);height:var(--sz);animation:spin var(--spd) linear infinite}
.sp-arc circle{fill:none;stroke:var(--clr);stroke-width:4;stroke-linecap:round;stroke-dasharray:60 100;animation:arc-pulse calc(var(--spd)*2) ease-in-out infinite}
@keyframes arc-pulse{0%,100%{stroke-dasharray:15 100}50%{stroke-dasharray:80 100}}
/* 4. Bounce dots */
.sp-bounce{display:flex;gap:6px;align-items:center;height:var(--sz)}
.sp-bounce span{width:10px;height:10px;border-radius:50%;background:var(--clr);animation:bounce var(--spd) ease-in-out infinite}
.sp-bounce span:nth-child(2){animation-delay:calc(var(--spd)*0.15)}
.sp-bounce span:nth-child(3){animation-delay:calc(var(--spd)*0.3)}
@keyframes bounce{0%,100%{transform:translateY(0)}50%{transform:translateY(-14px)}}
/* 5. Pulse ring */
.sp-pulse{width:var(--sz);height:var(--sz);border-radius:50%;background:rgba(88,166,255,.15);border:2px solid var(--clr);animation:pulse-ring var(--spd) ease-out infinite}
@keyframes pulse-ring{0%{transform:scale(.8);opacity:1}100%{transform:scale(1.5);opacity:0}}
/* 6. Square rotate */
.sp-square{width:calc(var(--sz)*0.65);height:calc(var(--sz)*0.65);border:3px solid var(--clr);animation:sq-spin var(--spd) ease-in-out infinite}
@keyframes sq-spin{0%{transform:rotate(0deg)}50%{transform:rotate(180deg) scale(.7)}100%{transform:rotate(360deg)}}
/* See inside and Compare. Every added part is made once and kept drawn, so Pause, Slow motion and the Speed rescale reach it;
the drawings and the scene's ring take their sizes, colors and turn times from --sz, --clr and --spd. */
.stage{position:relative}
.grid .spin-box{display:contents}
.dr,.spin-cap,.spin-half{display:none}
.dr{position:absolute;left:50%;top:50%;translate:-50% -50%;color:var(--clr);opacity:.6;pointer-events:none}
.dr-turn{width:calc(var(--sz) + 26px);height:calc(var(--sz) + 26px)}
.dr-turn path{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;vector-effect:non-scaling-stroke}
.dr-circ,.dr-sq{width:calc(var(--sz)*var(--k));height:calc(var(--sz)*var(--k));border:1.5px dashed currentColor}
.dr-circ{border-radius:50%}
.dr-hop{width:52px;height:0;border-top:1.5px dashed currentColor;translate:-50% 0}
.dr-hop.top{top:calc(50% - 19px)}
.dr-hop.base{top:calc(50% + 5px)}
.cmp{position:absolute;inset:0;display:grid;grid-template-columns:repeat(2,minmax(0,340px));justify-content:center;gap:clamp(8px,2.5vw,14px);padding:clamp(10px,3vw,16px);visibility:hidden;pointer-events:none}
.half{display:flex;flex-direction:column;align-items:flex-start;gap:8px;min-width:0}
.spin-half{padding:3px 9px;border:1px solid var(--ui-border);border-radius:6px;background:rgba(8,8,10,.9);color:#f4f4f2;font:600 13px/1.2 var(--hb-font);white-space:nowrap}
.panel{align-self:stretch;flex:1;min-height:0;display:flex;flex-direction:column;gap:8px;padding:10px;background:var(--ui-bg);border:1px solid var(--ui-border);border-radius:8px}
.panel-title{font:600 13px/1.2 var(--hb-font);color:#d6d6dc}
.panel-body{flex:1;min-height:0;display:grid;place-items:center;border:1px dashed rgba(255,255,255,.18);border-radius:6px}
.cmp .spin-box,.stage[data-hb-mode="inside"] .grid .spin-box{display:grid;place-items:center;position:relative;width:calc(var(--sz) + 28px);height:calc(var(--sz) + 28px)}
.cmp .spin-box>:not(.dr),.stage[data-hb-mode="inside"] .spin-box>:not(.dr){position:relative}
/* See inside: the grid fills the box, each cell a spinner with its drawing and, beside it, its name and what it is made of */
.stage[data-hb-mode="inside"]{padding:12px}
.stage[data-hb-mode="inside"] .grid{max-width:none;height:100%;grid-template-rows:repeat(2,minmax(0,1fr));gap:10px}
.stage[data-hb-mode="inside"] .spin-cell{display:grid;grid-template-columns:auto minmax(0,210px);justify-content:center;grid-template-rows:1fr auto auto 1fr;column-gap:12px;row-gap:3px;align-items:start;min-width:0;padding:6px 10px;text-align:left}
.stage[data-hb-mode="inside"] .spin-box{grid-row:1/-1;align-self:center}
.stage[data-hb-mode="inside"] .spin-label{grid-column:2;grid-row:2;font-size:12px;text-align:left}
.stage[data-hb-mode="inside"] .spin-cap{display:block;grid-column:2;grid-row:3;color:#e9e9ee;font:400 12.5px/1.3 var(--hb-font)}
.stage[data-hb-mode="inside"] .dr{display:block}
/* Compare: the six spinners step aside, out of the flow but still turning, and the scene shows */
.stage[data-hb-mode="compare"] .grid{position:absolute;visibility:hidden}
.stage[data-hb-mode="compare"] .cmp{visibility:visible}
.stage[data-hb-mode="compare"] .spin-half{display:block}
@media(max-width:760px){
.stage[data-hb-mode="inside"]{padding:10px}
.stage[data-hb-mode="inside"] .spin-cell{column-gap:8px;padding:4px 8px}
.stage[data-hb-mode="inside"] .spin-cap{font-size:12px;line-height:1.25}
}
/* Narrow boxes show Ring, Orbit and Bounce only: the other three step aside, out of the flow but still turning. Up to 600
wide they stack in one column; from 601 to 660 they stand in a row, each with its name and words under the spinner. */
@media(max-width:660px){
.stage[data-hb-mode="inside"] .spin-cell:is(:nth-child(3),:nth-child(n+5)){position:absolute;visibility:hidden}
}
@media(max-width:600px){
.stage[data-hb-mode="inside"]{padding:8px}
.stage[data-hb-mode="inside"] .grid{grid-template-columns:minmax(0,1fr);grid-template-rows:repeat(3,minmax(0,1fr));gap:6px}
}
@media(min-width:601px) and (max-width:660px){
.stage[data-hb-mode="inside"] .grid{grid-template-rows:minmax(0,1fr)}
.stage[data-hb-mode="inside"] .spin-cell{grid-template-columns:minmax(0,1fr);grid-template-rows:1fr auto auto auto 1fr;justify-items:center;text-align:center}
.stage[data-hb-mode="inside"] :is(.spin-box,.spin-label,.spin-cap){grid-column:1;text-align:center}
.stage[data-hb-mode="inside"] .spin-box{grid-row:2}
.stage[data-hb-mode="inside"] .spin-label{grid-row:3}
.stage[data-hb-mode="inside"] .spin-cap{grid-row:4}
}
/* Paused at time zero the bounce dots sit level: in See inside they start part way in, each 15% of a turn after the one before */
@media(prefers-reduced-motion:reduce){
.stage[data-hb-mode="inside"] .sp-bounce span{animation-delay:calc(var(--spd)*-.4)}
.stage[data-hb-mode="inside"] .sp-bounce span:nth-child(2){animation-delay:calc(var(--spd)*-.25)}
.stage[data-hb-mode="inside"] .sp-bounce span:nth-child(3){animation-delay:calc(var(--spd)*-.1)}
.cmp .dr-turn{display:block}
}
</style>
<link rel="stylesheet" href="../../../assets/css/demo-page.css?v=11">
<script src="../../../assets/js/demo-page.js?v=11" defer></script>
</head>
<body class="hb" data-hb-kind="loop">
<nav class="hb-bar" aria-label="Animation Handbook">
<a class="hb-home" href="../../../"><svg class="hb-mark" viewBox="0 0 32 32" aria-hidden="true"><g class="g"><circle cx="11.16" cy="20.84" r="6.1"/><circle cx="15.12" cy="16.88" r="6.1"/><circle cx="18.51" cy="13.49" r="6.1"/></g><circle class="b" cx="21.2" cy="10.8" r="6.6"/></svg><span>Animation Handbook</span></a>
<span class="hb-pager"><a href="../shimmer-effect/" rel="prev" aria-label="Previous: Shimmer Effect"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6"/></svg><span><span class="hb-dir">Previous: </span>Shimmer Effect</span></a><a href="../progress-animation/" rel="next" aria-label="Next: Progress Animation"><span><span class="hb-dir">Next: </span>Progress Animation</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 18 6-6-6-6"/></svg></a></span>
<a class="hb-star" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener" aria-label="Star on GitHub"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg><span>Star on GitHub</span></a>
</nav>
<main class="hb-page">
<header class="hb-head">
<p class="hb-cat">04.11 · Micro-Interactions</p>
<h1>Loading Spinner</h1>
<p class="hb-lede">Six small shapes loop to show that something is loading. Best for short waits.</p>
</header>
<section class="hb-step hb-watch" aria-labelledby="hb-watch-title">
<div class="hb-step-head">
<span class="hb-num" aria-hidden="true">1</span>
<div><h2 id="hb-watch-title">Watch it</h2><p>It moves by itself. Pause it to look closely, or turn on slow motion to see each part of the movement.</p></div>
</div>
<div class="seg hb-modes" role="group" aria-label="What the box shows" data-hb-modes>
<button type="button" data-hb-mode="normal" class="on" aria-pressed="true">Normal</button>
<button type="button" data-hb-mode="inside" aria-pressed="false">See inside</button>
<button type="button" data-hb-mode="compare" aria-pressed="false">Compare</button>
</div>
<div class="stage hb-dots">
<div class="grid">
<div class="spin-cell">
<div class="spin-box">
<svg class="dr dr-turn" viewBox="0 0 100 100" aria-hidden="true"><path d="M10.2 27A46 46 0 1 1 73 89.8M82.4 93.6L69.5 91.8L74.4 79.8"/></svg>
<div class="sp-ring" role="status" aria-label="Loading"></div>
</div>
<div class="spin-label">Ring</div>
<p class="spin-cap" id="ring-cap" aria-hidden="true" data-hb-caption>The ring turns a little more than once a second</p>
</div>
<div class="spin-cell">
<div class="spin-box">
<svg class="dr dr-turn" viewBox="0 0 100 100" aria-hidden="true"><path d="M10.2 27A46 46 0 1 1 73 89.8M82.4 93.6L69.5 91.8L74.4 79.8"/></svg>
<div class="sp-dots" role="status" aria-label="Loading">
<span></span><span></span><span></span><span></span><span></span><span></span>
</div>
</div>
<div class="spin-label">Orbit</div>
<p class="spin-cap" aria-hidden="true" data-hb-caption>Six dots, each fainter than the last, turning as one</p>
</div>
<div class="spin-cell">
<div class="spin-box">
<i class="dr dr-circ" style="--k:.8" aria-hidden="true"></i>
<svg class="sp-arc" viewBox="0 0 40 40" role="status" aria-label="Loading">
<circle cx="20" cy="20" r="16"/>
</svg>
</div>
<div class="spin-label">Arc</div>
<p class="spin-cap" aria-hidden="true" data-hb-caption>The colored part grows and shrinks as it turns</p>
</div>
<div class="spin-cell">
<div class="spin-box">
<i class="dr dr-hop top" aria-hidden="true"></i><i class="dr dr-hop base" aria-hidden="true"></i>
<div class="sp-bounce" role="status" aria-label="Loading">
<span></span><span></span><span></span>
</div>
</div>
<div class="spin-label">Bounce</div>
<p class="spin-cap" aria-hidden="true" data-hb-caption>The same hop, each dot a little later</p>
</div>
<div class="spin-cell">
<div class="spin-box">
<i class="dr dr-circ" style="--k:.8" aria-hidden="true"></i><i class="dr dr-circ" style="--k:1.5" aria-hidden="true"></i>
<div class="sp-pulse" role="status" aria-label="Loading"></div>
</div>
<div class="spin-label">Pulse</div>
<p class="spin-cap" aria-hidden="true" data-hb-caption>Grows from the inner circle to the outer one, fading out</p>
</div>
<div class="spin-cell">
<div class="spin-box">
<i class="dr dr-sq" style="--k:.455" aria-hidden="true"></i>
<div class="sp-square" role="status" aria-label="Loading"></div>
</div>
<div class="spin-label">Square</div>
<p class="spin-cap" aria-hidden="true" data-hb-caption>Turns half way while shrinking, then grows back</p>
</div>
</div>
<div class="cmp" aria-hidden="true" inert>
<div class="half">
<p class="spin-half" data-hb-caption>Looks stuck</p>
<div class="panel"><p class="panel-title">Your files</p><div class="panel-body"></div></div>
</div>
<div class="half">
<p class="spin-half" data-hb-caption>With a spinner</p>
<div class="panel"><p class="panel-title">Your files</p><div class="panel-body">
<div class="spin-box">
<svg class="dr dr-turn" viewBox="0 0 100 100" aria-hidden="true"><path d="M10.2 27A46 46 0 1 1 73 89.8M82.4 93.6L69.5 91.8L74.4 79.8"/></svg>
<div class="sp-ring"></div>
</div>
</div></div>
</div>
</div>
</div>
<div class="hb-player">
<button class="hb-play" type="button" id="btn-pause" data-hb-pause="css" data-state="playing"><svg class="hb-ic hb-i-pause" viewBox="0 0 24 24" aria-hidden="true"><rect x="6" y="4" width="4" height="16" rx="1"/><rect x="14" y="4" width="4" height="16" rx="1"/></svg><svg class="hb-ic hb-i-play" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3l14 9-14 9z"/></svg><span class="hb-pause-label">Pause</span></button>
<label class="hb-toggle"><input class="hb-switch" type="checkbox" role="switch" id="slow-tog" data-hb-slowmo="css" autocomplete="off"><span>Slow motion</span></label>
</div>
<div class="hb-mode-notes" aria-live="polite">
<p data-hb-for="inside" hidden>Inside, each spinner is taken apart: what turns, what fades, and what starts a little later. They all loop until the wait is over.</p>
<p data-hb-for="compare" hidden>Looks stuck: an empty box, so you cannot tell whether anything is happening; With a spinner: the turning ring shows the page is still working.</p>
</div>
</section>
<section class="hb-step hb-try" aria-labelledby="hb-try-title">
<div class="hb-step-head">
<span class="hb-num" aria-hidden="true">2</span>
<div><h2 id="hb-try-title">Try it</h2><p>Change a setting and see the difference as it moves.</p></div>
</div>
<div class="hb-settings">
<div class="hb-setting">
<p class="hb-setting-name" id="speed-lbl">Speed</p>
<div class="seg" id="speed-seg" role="group" aria-labelledby="speed-lbl">
<button type="button" data-ms="1300" aria-pressed="false">Slow</button>
<button type="button" data-ms="800" class="on" aria-pressed="true">Normal</button>
<button type="button" data-ms="500" aria-pressed="false">Fast</button>
</div>
<p class="hb-hint">Fast spinning can feel anxious.</p>
</div>
<div class="hb-setting">
<p class="hb-setting-name" id="size-lbl">Size</p>
<div class="seg" id="size-seg" role="group" aria-labelledby="size-lbl">
<button type="button" data-px="28" aria-pressed="false">Small</button>
<button type="button" data-px="40" class="on" aria-pressed="true">Medium</button>
<button type="button" data-px="52" aria-pressed="false">Large</button>
</div>
<p class="hb-hint">Small fits inside a button; large fills an empty area.</p>
</div>
</div>
<details class="hb-options">
<summary><span class="hb-more-label">More options</span><span class="hb-less">Fewer options</span><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg></summary>
<div class="hb-settings">
<div class="hb-setting">
<p class="hb-setting-name" id="color-lbl">Color</p>
<div class="swatches" id="color-sw" role="group" aria-labelledby="color-lbl">
<button type="button" aria-pressed="false" aria-label="Pink" data-c="#ff6f8b" style="background:#ff6f8b"></button>
<button type="button" aria-pressed="false" aria-label="White" data-c="#f4f4f2" style="background:#f4f4f2"></button>
<button type="button" class="on" aria-pressed="true" aria-label="Blue" data-c="#58a6ff" style="background:#58a6ff"></button>
<button type="button" aria-pressed="false" aria-label="Purple" data-c="#d2a8ff" style="background:#d2a8ff"></button>
<button type="button" aria-pressed="false" aria-label="Green" data-c="#56d364" style="background:#56d364"></button>
<button type="button" aria-pressed="false" aria-label="Orange" data-c="#ffa657" style="background:#ffa657"></button>
</div>
<p class="hb-hint">Pick a color that stands out from the page.</p>
</div>
</div>
</details>
</section>
<section class="hb-step hb-prompt-step" aria-labelledby="hb-prompt-title">
<div class="hb-step-head">
<span class="hb-num" aria-hidden="true">3</span>
<div><h2 id="hb-prompt-title">Copy the prompt</h2><p>Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.</p></div>
</div>
<div class="hb-card">
<p class="hb-prompt">Add a loading spinner to [the place where people wait for something to load]. Use a small shape that keeps moving in a steady loop, such as a ring with one colored part turning around, dots circling or dots bouncing in turn, to show that work is going on when you cannot say how long it will take. Show it only for waits longer than about half a second, and tell screen readers that something is loading. If you know how far along the task is, use a progress bar instead. If the visitor has reduced motion turned on, fade it gently instead of spinning. Match the settings listed below.</p>
<div class="hb-chips-box" hidden>
<p class="hb-chips-title">Your settings</p>
<ul class="hb-chips"></ul>
</div>
<div class="hb-copy-row">
<button class="hb-copy" type="button"><svg class="hb-ic hb-i-copy" viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg><svg class="hb-ic hb-i-done" viewBox="0 0 24 24" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg><span class="hb-copy-label" aria-live="polite">Copy prompt</span></button>
<p class="hb-hint">Replace the words in brackets with your own element. Your settings are added at the end.</p>
</div>
</div>
<div class="hb-star-row"><p>Free and open source. If this helped, a star on GitHub helps other people find it.</p><a class="hb-star-btn" href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener"><svg class="hb-ic" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>Star on GitHub</a></div>
</section>
<section class="hb-about" aria-labelledby="hb-what-title">
<div class="hb-what">
<h2 id="hb-what-title">What it is</h2>
<div class="hb-what-text"><p>The full explanation is in <a href="README.md">README.md</a>.</p></div>
</div>
<div class="hb-fit">
<h2>Good for</h2>
<ul class="hb-tags hb-good"><li>Network waits</li><li>Buttons while sending</li><li>Short waits</li></ul>
<h3>Avoid on</h3>
<ul class="hb-tags hb-avoid"><li>Known-length tasks</li><li>Very quick loads</li></ul>
</div>
</section>
<section class="hb-related" aria-labelledby="hb-related-title" hidden>
<h2 id="hb-related-title">Similar animations</h2>
<div class="hb-rel-list"></div>
</section>
</main>
<footer class="hb-foot"><span>Animation Handbook</span><a href="https://github.com/matinmonshizadeh/animation-handbook" target="_blank" rel="noopener">Source on GitHub</a><a href="#top">Back to top ↑</a></footer>
<script>
const stage=document.querySelector('.stage');
const vars=document.documentElement.style;
const pulse=document.querySelector('.sp-pulse');
let turnMs=800;
// The Ring's caption says how often it turns, from the same turn time and Slow motion that move it
const slowTog=document.getElementById('slow-tog'),ringCap=document.getElementById('ring-cap');
function turnWords(){
const s=turnMs*(slowTog.checked?3:1)/1000;
if(s<.6)return 'twice a second';
if(s<1)return 'a little more than once a second';
if(s<1.4)return 'about once every second and a quarter';
if(s<2)return 'about once every second and a half';
if(s<3)return 'about once every two and a half seconds';
return 'about once every four seconds';
}
function ringWords(){
const words='The ring turns '+turnWords();
if(ringCap.textContent!==words)ringCap.textContent=words;
}
// Under reduced motion the loop starts paused, so both views are stills and their notes say so; once Play moves them the notes
// say the markup's own words again. hb:pause is sent on every Pause and Play, and once at boot under reduced motion.
const reduceMQ=matchMedia('(prefers-reduced-motion: reduce)');
const notes=[...document.querySelectorAll('[data-hb-for]')],moving=notes.map(n=>n.textContent),still=[
'Inside, each spinner is taken apart, shown still: what turns, what fades, and what starts a little later.',
'Shown still: Looks stuck is an empty box; With a spinner has a ring that turns while the page works, so people know to wait.'];
let paused=reduceMQ.matches;
function describe(){
notes.forEach((n,i)=>{const words=reduceMQ.matches&&paused?still[i]:moving[i];if(n.textContent!==words)n.textContent=words});
}
document.addEventListener('hb:pause',e=>{paused=e.detail.paused;describe()});
// The page's only named picture is the Arc spinner's own, so each view names the box (a group, only while it shows)
const names={inside:'Each loading spinner taken apart to show what moves',compare:'A box with no spinner beside the same box with a spinner turning'};
document.addEventListener('hb:mode',e=>{
const name=names[e.detail.mode];
if(name){stage.setAttribute('role','group');stage.setAttribute('aria-label',name)}
else{stage.removeAttribute('role');stage.removeAttribute('aria-label')}
describe();ringWords();
});
// The shared script switches Slow motion off after this listener runs, so the Ring's words follow a moment later
reduceMQ.addEventListener('change',()=>{describe();setTimeout(ringWords)});
slowTog.addEventListener('change',ringWords);
function choices(id,pick){
const buttons=document.querySelectorAll('#'+id+' button');
buttons.forEach(b=>b.addEventListener('click',()=>{
buttons.forEach(x=>{x.classList.toggle('on',x===b);x.setAttribute('aria-pressed',String(x===b))});
pick(b.dataset);
}));
}
// A new --spd keeps the time already played, so every spinner would jump to another point of its turn.
// Scaling each animation's time by the same factor as its length keeps them where they are, moving or paused.
choices('speed-seg',d=>{
const next=+d.ms;
stage.getAnimations({subtree:true}).forEach(a=>{if(a.currentTime!=null)a.currentTime=a.currentTime*next/turnMs});
turnMs=next;
vars.setProperty('--spd',next+'ms');
ringWords();
});
choices('size-seg',d=>{vars.setProperty('--sz',d.px+'px')});
// The Pulse spinner also fills its ring with the color at 15% opacity (26 is 15% written in hex)
choices('color-sw',d=>{
vars.setProperty('--clr',d.c);
pulse.style.background=d.c+'26';
});
</script>
</body>
</html>