Chapter stepper
A story in three steps that plays by itself: title and paragraph appear word by word on the left, a drawn illustration assembles on the right, and a segmented progress bar at the bottom fills per chapter. Clicking a segment or Skip takes over and stops the autoplay. Without the script the chapters are simply stacked.
Part of the style
Toon Orbit
7 parts that belong together, with their tokens, type and rules.
https://kitbash.me/components/toon-orbit/chapters/figma.html?palette=495b52b11a798b42
Use the Figma MCP server (https://mcp.figma.com/mcp). Download https://kitbash.me/components/toon-orbit/chapters/figma.html?palette=495b52b11a798b42 and pass that whole HTML document to the html_to_figma tool, so the part "Chapter stepper" lands as editable layers in my open Figma file. Fonts come from Google Fonts: if a face is missing in Figma, pick the closest one.
Code
<style>
/* Goes after the pack's base.css */
:root {
--field: #8abd86;
--hairline: rgba(3, 3, 6, 0.16);
--glow: rgba(3, 3, 6, 0.32);
--lilac: #030306;
--lilac-dim: rgba(3, 3, 6, 0.62);
--paper: #000001;
--plum-ink: #8abd86;
--lime: #0d4560;
--lime-shade: #09425d;
--lime-deep: #042638;
--signal: #00344c;
--pink: #0a5248;
--orchid: #04443b;
--void: #607b75;
--rock: #4b8076;
--stone: #087365;
--line: #4a8076;
--orchid-shade: #146e60;
--pink-shade: #12695c;
--field-glow: #94ffea;
--field-deep: #b5f3e6;
--pink-deep: #038e7c;
--orchid-deep: #0b8474;
--rock-shade: #557e75;
--rock-deep: #5c7c75;
--stone-shade: #208e7e;
--stone-deep: #1f8676;
--glass: rgba(96, 123, 117, 0.5);
}
</style>
<section class="chapters" aria-label="How a box is made">
<svg class="chapters__symbols" width="0" height="0" aria-hidden="true">
<defs>
<symbol id="chapters-rock" viewBox="0 0 160 150">
<polygon class="chapters__face-a" points="30,26 70,8 118,14 104,52 52,60"/>
<polygon class="chapters__face-b" points="8,70 30,26 52,60 44,104 14,108"/>
<polygon class="chapters__face-b" points="52,60 104,52 112,104 44,104"/>
<polygon class="chapters__face-c" points="118,14 150,44 154,92 112,104 104,52"/>
<polygon class="chapters__face-c" points="14,108 44,104 40,138"/>
<polygon class="chapters__face-c" points="44,104 112,104 130,126 92,144 40,138"/>
<polygon class="chapters__face-c" points="112,104 154,92 130,126"/>
<polygon class="chapters__rim" points="8,70 30,26 70,8 118,14 150,44 154,92 130,126 92,144 40,138 14,108"/>
</symbol>
<symbol id="chapters-crystal" viewBox="0 0 100 200">
<polygon class="chapters__face-a" points="50,2 15,45 45,55"/>
<polygon class="chapters__face-b" points="50,2 45,55 85,40"/>
<polygon class="chapters__face-a" points="15,45 45,55 45,160 15,150"/>
<polygon class="chapters__face-b" points="45,55 85,40 85,145 45,160"/>
<polygon class="chapters__face-b" points="15,150 45,160 50,198"/>
<polygon class="chapters__face-c" points="45,160 85,145 50,198"/>
<polygon class="chapters__rim" points="50,2 85,40 85,145 50,198 15,150 15,45"/>
</symbol>
<symbol id="chapters-gem" viewBox="0 0 120 120">
<polygon class="chapters__face-a" points="60,30 88.5,50.7 77.6,84.3 42.4,84.3 31.5,50.7"/>
<polygon class="chapters__face-a" points="31.5,50.7 6.7,42.7 27.1,14.7 60,4 60,30"/>
<polygon class="chapters__face-b" points="60,30 60,4 92.9,14.7 113.3,42.7 88.5,50.7"/>
<polygon class="chapters__face-b" points="42.4,84.3 27.1,105.3 6.7,77.3 6.7,42.7 31.5,50.7"/>
<polygon class="chapters__face-c" points="88.5,50.7 113.3,42.7 113.3,77.3 92.9,105.3 77.6,84.3"/>
<polygon class="chapters__face-c" points="77.6,84.3 92.9,105.3 60,116 27.1,105.3 42.4,84.3"/>
<polygon class="chapters__rim" points="60,4 92.9,14.7 113.3,42.7 113.3,77.3 92.9,105.3 60,116 27.1,105.3 6.7,77.3 6.7,42.7 27.1,14.7"/>
</symbol>
</defs>
</svg>
<div class="chapters__stage">
<article class="chapters__chapter">
<div class="chapters__text">
<h2 class="chapters__title">Quarried by hand.</h2>
<p class="chapters__lead">Our pickers work small family quarries in four countries. Nothing is blasted, dyed or glued. What the hill gives up is what you get.</p>
</div>
<svg class="chapters__art" viewBox="0 0 400 400" aria-hidden="true">
<use class="chapters__piece chapters__paint-rock" href="#chapters-rock" x="60" y="90" width="290" height="272" style="rotate: -8deg"/>
<use class="chapters__piece chapters__paint-stone" href="#chapters-rock" x="20" y="250" width="130" height="122" style="rotate: 28deg"/>
<use class="chapters__piece chapters__paint-stone" href="#chapters-rock" x="290" y="40" width="80" height="75" style="rotate: -30deg"/>
<use class="chapters__piece chapters__paint-pink" href="#chapters-crystal" x="40" y="60" width="40" height="80" style="rotate: -24deg"/>
</svg>
</article>
<article class="chapters__chapter">
<div class="chapters__text">
<h2 class="chapters__title">Sorted by eye.</h2>
<p class="chapters__lead">Each month has one theme: a colour, a habit, a place. Three specimens are picked to tell it, and no two boxes are quite the same.</p>
</div>
<svg class="chapters__art" viewBox="0 0 400 400" aria-hidden="true">
<use class="chapters__piece chapters__paint-orchid" href="#chapters-crystal" x="150" y="40" width="130" height="260" style="rotate: 6deg"/>
<use class="chapters__piece chapters__paint-pink" href="#chapters-crystal" x="60" y="130" width="100" height="200" style="rotate: -18deg"/>
<use class="chapters__piece chapters__paint-orchid" href="#chapters-crystal" x="260" y="150" width="84" height="168" style="rotate: 24deg"/>
<use class="chapters__piece chapters__paint-rock" href="#chapters-rock" x="70" y="270" width="270" height="110"/>
<use class="chapters__piece chapters__paint-lime" href="#chapters-crystal" x="330" y="50" width="30" height="60" style="rotate: 40deg"/>
</svg>
</article>
<article class="chapters__chapter">
<div class="chapters__text">
<h2 class="chapters__title">Yours to keep.</h2>
<p class="chapters__lead">The box lands with a field card for every stone: where it formed, how old it is and why it looks the way it does.</p>
</div>
<svg class="chapters__art" viewBox="0 0 400 400" aria-hidden="true">
<use class="chapters__piece chapters__paint-lime" href="#chapters-gem" x="80" y="80" width="240" height="240"/>
<use class="chapters__piece chapters__paint-pink" href="#chapters-crystal" x="320" y="230" width="44" height="88" style="rotate: 30deg"/>
<use class="chapters__piece chapters__paint-stone" href="#chapters-rock" x="30" y="50" width="76" height="71"/>
<use class="chapters__piece chapters__paint-rock" href="#chapters-rock" x="270" y="20" width="90" height="84" style="rotate: 50deg"/>
</svg>
</article>
</div>
<div class="chapters__controls">
<button class="chapters__skip" type="button">Skip</button>
<div class="chapters__bar"></div>
</div>
</section>
<style>
.chapters {
position: relative;
display: grid;
gap: var(--space-5);
padding: var(--space-7) var(--space-4) var(--space-4);
overflow: hidden;
background:
radial-gradient(ellipse 50% 60% at 78% 45%, var(--field-glow), transparent 72%),
var(--field);
}
.chapters__symbols { position: absolute; }
.chapters__stage {
display: grid;
gap: var(--space-6);
width: 100%;
max-width: var(--page);
margin: 0 auto;
}
.chapters__chapter {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 0.8fr);
align-items: center;
gap: var(--space-5);
}
/* With the script running, chapters share one cell and take turns. */
.chapters--live .chapters__chapter {
grid-area: 1 / 1;
visibility: hidden;
opacity: 0;
transition: opacity var(--time-reveal) var(--ease-cubic), visibility 0s var(--time-reveal);
}
.chapters--live .chapters__chapter--current {
visibility: visible;
opacity: 1;
transition-delay: 0s;
}
.chapters__text { max-width: 34rem; justify-self: center; }
.chapters__title {
margin: 0 0 var(--space-3);
font-size: var(--text-title);
font-weight: 500;
line-height: 1.08;
letter-spacing: var(--tracking-display);
text-shadow: 0 0 0.6em var(--glow);
}
.chapters__lead {
margin: 0;
color: var(--lilac-dim);
font-size: var(--text-lead);
line-height: 1.35;
text-wrap: pretty;
}
.chapters__word {
display: inline-block;
opacity: 0;
filter: blur(10px);
}
.chapters__chapter--current .chapters__word {
opacity: 1;
filter: none;
transition:
opacity var(--time-settle) var(--ease-cubic) calc(var(--chapters-order) * var(--stagger-word) + var(--time-quick)),
filter var(--time-settle) var(--ease-cubic) calc(var(--chapters-order) * var(--stagger-word) + var(--time-quick));
}
.chapters__art {
display: block;
width: 100%;
max-width: 460px;
margin: 0 auto;
overflow: visible;
animation: chapters-float var(--time-drift) ease-in-out infinite alternate;
}
.chapters__piece {
transform-box: fill-box;
transform-origin: center;
}
.chapters--live .chapters__piece { scale: 0; }
.chapters--live .chapters__chapter--current .chapters__piece {
scale: 1;
transition: scale var(--time-settle) var(--ease-expo);
}
.chapters__chapter--current .chapters__piece:nth-child(2) { transition-delay: var(--stagger-item); }
.chapters__chapter--current .chapters__piece:nth-child(3) { transition-delay: calc(var(--stagger-item) * 2); }
.chapters__chapter--current .chapters__piece:nth-child(4) { transition-delay: calc(var(--stagger-item) * 3); }
.chapters__chapter--current .chapters__piece:nth-child(5) { transition-delay: calc(var(--stagger-item) * 4); }
.chapters__paint-rock { --chapters-a: var(--rock); --chapters-b: var(--rock-shade); --chapters-c: var(--rock-deep); }
.chapters__paint-stone { --chapters-a: var(--stone); --chapters-b: var(--stone-shade); --chapters-c: var(--stone-deep); }
.chapters__paint-orchid { --chapters-a: var(--orchid); --chapters-b: var(--orchid-shade); --chapters-c: var(--orchid-deep); }
.chapters__paint-pink { --chapters-a: var(--pink); --chapters-b: var(--pink-shade); --chapters-c: var(--pink-deep); }
.chapters__paint-lime { --chapters-a: var(--lime); --chapters-b: var(--lime-shade); --chapters-c: var(--lime-deep); }
.chapters__face-a { fill: var(--chapters-a); }
.chapters__face-b { fill: var(--chapters-b); }
.chapters__face-c { fill: var(--chapters-c); }
.chapters__face-a, .chapters__face-b, .chapters__face-c { stroke: var(--chapters-c); stroke-width: 1; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chapters__rim { fill: none; stroke: var(--line); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chapters__controls {
display: none;
justify-items: center;
gap: var(--space-2);
width: 100%;
max-width: var(--page);
margin: 0 auto;
}
.chapters--live .chapters__controls { display: grid; }
.chapters__skip {
min-width: var(--tap);
min-height: var(--tap);
padding: 0 var(--space-3);
border: 0;
background: none;
color: var(--lilac-dim);
font: inherit;
font-size: var(--text-small);
font-weight: 500;
cursor: pointer;
transition: color var(--time-quick) var(--ease-cubic);
}
.chapters__skip:hover,
.chapters__skip:focus-visible { color: var(--lilac); }
.chapters__bar {
display: flex;
gap: var(--space-2);
width: 100%;
}
/* The button is tall enough to tap, the line inside it is thin. */
.chapters__segment {
flex: 1;
display: grid;
align-items: center;
height: var(--tap);
padding: 0;
border: 0;
background: none;
cursor: pointer;
}
.chapters__track {
display: block;
height: 3px;
overflow: hidden;
border-radius: var(--radius-bar);
background: var(--hairline);
transition: height var(--time-quick) var(--ease-cubic);
}
.chapters__segment:hover .chapters__track { height: 5px; }
.chapters__fill {
display: block;
height: 100%;
background: var(--lilac);
transform: scaleX(0);
transform-origin: left;
}
.chapters__segment--done .chapters__fill { transform: none; }
.chapters__segment--current .chapters__fill { animation: chapters-fill var(--time-chapter) linear forwards; }
.chapters--resting .chapters__segment--current .chapters__fill { animation-play-state: paused; }
.chapters--manual .chapters__segment--current .chapters__fill { animation: none; transform: none; }
@keyframes chapters-fill { to { transform: none; } }
@keyframes chapters-float {
from { translate: 0 -8px; rotate: -1.5deg; }
to { translate: 0 10px; rotate: 2deg; }
}
@media (max-width: 760px) {
.chapters { padding-top: var(--space-6); }
.chapters__chapter { grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
.chapters__art { grid-row: 1; max-width: 250px; }
.chapters--live .chapters__stage { min-height: 31rem; align-items: start; }
}
@media (prefers-reduced-motion: reduce) {
.chapters__art { animation: none; }
.chapters--live .chapters__chapter, .chapters__chapter--current .chapters__word, .chapters--live .chapters__chapter--current .chapters__piece, .chapters__track { transition: none; }
}
</style>
<script>
(() => {
function wrapWords(element, firstOrder) {
const words = element.textContent.trim().split(/\s+/);
element.setAttribute('aria-label', words.join(' '));
element.replaceChildren(...words.flatMap((word, index) => {
const span = document.createElement('span');
span.className = 'chapters__word';
span.style.setProperty('--chapters-order', firstOrder + index);
span.setAttribute('aria-hidden', 'true');
span.textContent = word;
return [span, ' '];
}));
return firstOrder + words.length;
}
function buildSegment(number) {
const segment = document.createElement('button');
segment.type = 'button';
segment.className = 'chapters__segment';
segment.setAttribute('aria-label', `Chapter ${number}`);
segment.innerHTML = '<span class="chapters__track"><span class="chapters__fill"></span></span>';
return segment;
}
function setUpChapters(root) {
const chapters = [...root.querySelectorAll('.chapters__chapter')];
const segments = chapters.map((_, index) => buildSegment(index + 1));
root.querySelector('.chapters__bar').replaceChildren(...segments);
for (const chapter of chapters) {
const wordsInTitle = wrapWords(chapter.querySelector('.chapters__title'), 0);
wrapWords(chapter.querySelector('.chapters__lead'), wordsInTitle + 3);
}
const show = (current) => {
chapters.forEach((chapter, index) => chapter.classList.toggle('chapters__chapter--current', index === current));
segments.forEach((segment, index) => {
segment.classList.toggle('chapters__segment--done', index < current);
segment.classList.toggle('chapters__segment--current', index === current);
segment.setAttribute('aria-current', String(index === current));
});
};
const stopTurning = () => root.classList.add('chapters--manual');
segments.forEach((segment, index) => {
segment.addEventListener('click', () => { stopTurning(); show(index); });
segment.addEventListener('animationend', () => show((index + 1) % chapters.length));
});
root.querySelector('.chapters__skip').addEventListener('click', () => { stopTurning(); show(chapters.length - 1); });
if (matchMedia('(prefers-reduced-motion: reduce)').matches) stopTurning();
new IntersectionObserver(([entry]) => root.classList.toggle('chapters--resting', !entry.isIntersecting), { threshold: 0.3 }).observe(root);
root.classList.add('chapters--live', 'chapters--resting');
show(0);
}
document.querySelectorAll('.chapters').forEach(setUpChapters);
})();
</script>