Chapter twoThe long way home
Chapter oneAn early start
import { useState } from 'react';
const SEATS = Array.from({ length: 60 }, (_, k) => ({ k, order: (k * 37) % 60 }));
const css = `
.slider-crowd { display: grid; justify-items: center; gap: 12px; width: 220px; }
.slider-crowd__room { display: grid; grid-template-columns: repeat(12, 12px); gap: 5px 4px; padding: 12px; border-radius: 12px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
/* Seats fill in a scattered order, the way people arrive. */
.slider-crowd__seat { position: relative; width: 12px; height: 14px; }
.slider-crowd__seat::before { content: ''; position: absolute; left: 3px; bottom: 0; width: 6px; height: 2px; border-radius: 1px; background: light-dark(#dbdde1, #2e3035); }
.slider-crowd__person { position: absolute; left: 2px; bottom: 1px; width: 8px; height: 12px; transform-origin: 50% 100%; transform: scale(clamp(0, calc((var(--slider-crowd-v) * 60 - var(--o)) * 2), 1)); transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
.slider-crowd__person::before { content: ''; position: absolute; left: 1.5px; top: 0; width: 5px; height: 5px; border-radius: 50%; background: light-dark(#42454c, #e5e6e9); }
.slider-crowd__person::after { content: ''; position: absolute; left: 0; bottom: 0; width: 8px; height: 6px; border-radius: 4px 4px 1px 1px; background: light-dark(#50535b, #c6c8cd); }
@media (prefers-reduced-motion: reduce) {
.slider-crowd__person { transition: none; }
}
.slider-crowd__read { color: light-dark(#50535b, #c6c8cd); font-size: 12px; font-variant-numeric: tabular-nums; }
.slider-crowd__read b { color: light-dark(#373a40, #f1f2f3); font-weight: 600; }
.slider-crowd__track { position: relative; width: 100%; height: 24px; }
.slider-crowd__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-crowd__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(10px + var(--slider-crowd-v) * (100% - 20px)); background: light-dark(#50535b, #c6c8cd); }
.slider-crowd__thumb { position: absolute; top: 2px; left: calc(var(--slider-crowd-v) * (100% - 20px)); width: 20px; height: 20px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); }
.slider-crowd:has(.slider-crowd__input:focus-visible) .slider-crowd__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-crowd__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-crowd__input::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; }
.slider-crowd__input::-moz-range-thumb { width: 20px; height: 20px; border: 0; }
`;
export function CrowdSlider() {
const [v, setV] = useState(48);
const t = (v - 0) / (120 - 0);
const word = v === 0 ? 'Empty' : v < 30 ? 'Quiet' : v < 70 ? 'Comfortable' : v < 100 ? 'Busy' : 'Packed';
return (
<>
<style>
{css}
</style>
<div className="slider-crowd" style={{ '--slider-crowd-v': t } as React.CSSProperties}>
<div className="slider-crowd__room" aria-hidden="true">
{SEATS.map((s) => (
<span key={s.k} className="slider-crowd__seat">
<span className="slider-crowd__person" style={{ '--o': s.order } as React.CSSProperties} />
</span>
))}
</div>
<span className="slider-crowd__read" aria-hidden="true">
<b>{v}</b> of 120 · {word}
</span>
<div className="slider-crowd__track">
<span className="slider-crowd__rail" />
<span className="slider-crowd__fill" />
<span className="slider-crowd__thumb" />
<input
className="slider-crowd__input"
type="range"
min={0}
max={120} step={2}
value={v}
onChange={(e) => setV(+e.target.value)}
aria-label="Expected guests"
aria-valuetext={`${v} of 120 guests, ${word.toLowerCase()}`}
/>
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initSliderCrowd(el) on the mounted element instead.
<div class="slider-crowd" style="--slider-crowd-v:0.4">
<div class="slider-crowd__room" aria-hidden="true">
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:0"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:37"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:14"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:51"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:28"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:5"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:42"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:19"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:56"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:33"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:10"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:47"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:24"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:1"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:38"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:15"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:52"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:29"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:6"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:43"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:20"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:57"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:34"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:11"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:48"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:25"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:2"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:39"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:16"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:53"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:30"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:7"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:44"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:21"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:58"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:35"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:12"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:49"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:26"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:3"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:40"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:17"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:54"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:31"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:8"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:45"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:22"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:59"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:36"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:13"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:50"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:27"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:4"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:41"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:18"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:55"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:32"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:9"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:46"></span>
</span>
<span class="slider-crowd__seat">
<span class="slider-crowd__person" style="--o:23"></span>
</span>
</div>
<span class="slider-crowd__read" aria-hidden="true"><b>48</b> of 120 · Comfortable</span>
<div class="slider-crowd__track">
<span class="slider-crowd__rail"></span>
<span class="slider-crowd__fill"></span>
<span class="slider-crowd__thumb"></span>
<input class="slider-crowd__input" type="range" min="0" max="120" step="2" aria-label="Expected guests" aria-valuetext="48 of 120 guests, comfortable" value="48"/>
</div>
</div>.slider-crowd { display: grid; justify-items: center; gap: 12px; width: 220px; }
.slider-crowd__room { display: grid; grid-template-columns: repeat(12, 12px); gap: 5px 4px; padding: 12px; border-radius: 12px; background: light-dark(#f3f4f7, #1a1c1f); box-shadow: inset 0 0 0 1px light-dark(#dbdde1, #2e3035); }
/* Seats fill in a scattered order, the way people arrive. */
.slider-crowd__seat { position: relative; width: 12px; height: 14px; }
.slider-crowd__seat::before { content: ''; position: absolute; left: 3px; bottom: 0; width: 6px; height: 2px; border-radius: 1px; background: light-dark(#dbdde1, #2e3035); }
.slider-crowd__person { position: absolute; left: 2px; bottom: 1px; width: 8px; height: 12px; transform-origin: 50% 100%; transform: scale(clamp(0, calc((var(--slider-crowd-v) * 60 - var(--o)) * 2), 1)); transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1); }
.slider-crowd__person::before { content: ''; position: absolute; left: 1.5px; top: 0; width: 5px; height: 5px; border-radius: 50%; background: light-dark(#42454c, #e5e6e9); }
.slider-crowd__person::after { content: ''; position: absolute; left: 0; bottom: 0; width: 8px; height: 6px; border-radius: 4px 4px 1px 1px; background: light-dark(#50535b, #c6c8cd); }
@media (prefers-reduced-motion: reduce) {
.slider-crowd__person { transition: none; }
}
.slider-crowd__read { color: light-dark(#50535b, #c6c8cd); font-size: 12px; font-variant-numeric: tabular-nums; }
.slider-crowd__read b { color: light-dark(#373a40, #f1f2f3); font-weight: 600; }
.slider-crowd__track { position: relative; width: 100%; height: 24px; }
.slider-crowd__rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 2px; background: light-dark(#ebedf0, #232529); }
.slider-crowd__fill { position: absolute; left: 0; top: 10px; height: 4px; border-radius: 2px; width: calc(10px + var(--slider-crowd-v) * (100% - 20px)); background: light-dark(#50535b, #c6c8cd); }
.slider-crowd__thumb { position: absolute; top: 2px; left: calc(var(--slider-crowd-v) * (100% - 20px)); width: 20px; height: 20px; border-radius: 50%; background: light-dark(#373a40, #f1f2f3); box-shadow: 0 2px 6px light-dark(rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.4)); }
.slider-crowd:has(.slider-crowd__input:focus-visible) .slider-crowd__thumb { outline: 2px solid light-dark(#50535b, #c6c8cd); outline-offset: 3px; }
.slider-crowd__input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; -webkit-appearance: none; appearance: none; background: none; }
.slider-crowd__input::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; }
.slider-crowd__input::-moz-range-thumb { width: 20px; height: 20px; border: 0; }function initSliderCrowd(root) {
var input = root.querySelector('.slider-crowd__input');
var read = root.querySelector('.slider-crowd__read');
function update() {
var v = +input.value;
var t = (v - 0) / (120 - 0);
root.style.setProperty('--slider-crowd-v', t);
var word = v === 0 ? 'Empty' : v < 30 ? 'Quiet' : v < 70 ? 'Comfortable' : v < 100 ? 'Busy' : 'Packed';
read.innerHTML = '<b>' + v + '</b> of 120 · ' + word;
input.setAttribute('aria-valuetext', v + ' of 120 guests, ' + word.toLowerCase());
}
input.addEventListener('input', update);
update();
return function () { input.removeEventListener('input', update); };
}
document.querySelectorAll('.slider-crowd').forEach(initSliderCrowd);Goal: Create a "Crowd" slider.
Visual behavior: An expected guests slider drawn as a room of seats: people pop into their seats in a scattered order as the number grows, the way a room fills up.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- The value is written to one CSS custom property (0 to 1) on the root; each of the 60 people has a fixed arrival order (--o) and scales up with clamp(0, (value * 60 - order) * 2, 1), on an overshooting transition.
- The order is (index * 37) mod 60, which scatters arrivals across the room rather than filling it row by row.
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the people appear without springing.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Crowd" slider.
Visual behavior: An expected guests slider drawn as a room of seats: people pop into their seats in a scattered order as the number grows, the way a room fills up.
Technique:
- A real <input type="range"> lies over the drawing, transparent (opacity 0, appearance none), with its thumb hit area sized to the drawn thumb, so dragging, clicking the track and the arrow, Page Up/Down, Home and End keys all work natively. The drawing is aria-hidden.
- The value is written to one CSS custom property (0 to 1) on the root; each of the 60 people has a fixed arrival order (--o) and scales up with clamp(0, (value * 60 - order) * 2, 1), on an overshooting transition.
- The order is (index * 37) mod 60, which scatters arrivals across the room rather than filling it row by row.
- :has(input:focus-visible) outlines the drawn thumb, so keyboard focus is visible though the input itself is not.
Accessibility: A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the people appear without springing.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
An expected guests slider drawn as a room of seats: people pop into their seats in a scattered order as the number grows, the way a room fills up.
A native range input with an aria-label and an aria-valuetext in words, so a screen reader announces the reading rather than a bare number; keyboard focus outlines the drawn thumb. Under prefers-reduced-motion the people appear without springing.