6 interactive playgrounds
Motion Lab
Tune timing, origin, and spring physics on the controls themselves.
Tactile press feedback
Hold each button. Tune the duration and scale on the right.
Code & AI prompt
.press-stage { display: grid; gap: 9px; padding: 15px; }
.press-stage .lab-control-row { min-height: 64px; }
.press-default { transition: transform 420ms ease 110ms; }
.press-default:active { transform: scale(.9); }
.press-tuned { transition: transform var(--press-duration, 160ms) cubic-bezier(.23,1,.32,1); }
.press-tuned:active { transform: scale(var(--press-scale,.97)); }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .001ms;
transition-duration: .001ms;
}
}const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const press = document.querySelector<HTMLElement>('.press-stage')!;
const duration = press.querySelector<HTMLInputElement>('[name="duration"]')!;
const scale = press.querySelector<HTMLInputElement>('[name="scale"]')!;
press.addEventListener('input', () => {
press.style.setProperty('--press-duration', `${duration.value}ms`);
press.style.setProperty('--press-scale', scale.value);
press.querySelector('output[for="press-duration"]')!.textContent = `${duration.value} ms`;
press.querySelector('output[for="press-scale"]')!.textContent = scale.value;
});Compare delayed feedback with a fast 160ms press at scale(.97). Expose duration and scale on labeled controls. Use explicit transform transitions and keep focus and reduced-motion behavior.Origin-aware popover
Open from any corner. Turn on center origin to compare.
Code & AI prompt
.pop-stage { width: min(100%,360px); height: 132px; position: relative; }
.pop-trigger { position: absolute; z-index: 2; }
.pop-trigger[data-corner="tl"] { inset: 0 auto auto 0; }
.pop-trigger[data-corner="tr"] { inset: 0 0 auto auto; }
.pop-trigger[data-corner="bl"] { inset: auto auto 0 0; }
.pop-trigger[data-corner="br"] { inset: auto 0 0 auto; }
.pop-panel {
position: absolute; inset: 35px auto auto 0; width: min(190px, 70%); padding: 7px 9px;
background: var(--canvas); border-radius: 8px; box-shadow: var(--shadow); z-index: 1;
transform-origin: var(--anchor-origin, center); opacity: 0; transform: scale(.95);
pointer-events: none; visibility: hidden;
transition: transform 160ms var(--ease-out), opacity 140ms, visibility 160ms;
font-size: .77rem;
}
.pop-panel[data-side="right"] { right: 0; left: auto; }
.pop-panel[data-edge="bottom"] { top: auto; bottom: 35px; }
.pop-panel[data-open="true"] { opacity: 1; transform: scale(1); visibility: visible; }
.pop-stage[data-naive="true"] .pop-panel { transform-origin: center; }
.pop-mode { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); display: flex; gap: 5px; align-items: center; color: var(--body); white-space: nowrap; font-size: .74rem; }
.pop-mode input { accent-color: var(--ink); }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .001ms;
transition-duration: .001ms;
}
}const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const stage = document.querySelector<HTMLElement>('.pop-stage')!;
const popup = stage.querySelector<HTMLElement>('.pop-panel')!;
const triggers = [...stage.querySelectorAll<HTMLButtonElement>('.pop-trigger')];
let trigger: HTMLButtonElement | undefined;
function closePopover(restore = false) {
popup.dataset.open = 'false';
popup.setAttribute('aria-hidden', 'true');
trigger?.setAttribute('aria-expanded', 'false');
if (restore) trigger?.focus();
trigger = undefined;
}
for (const button of triggers) {
button.addEventListener('click', () => {
const same = button === trigger;
closePopover();
if (same) return;
const [vertical, horizontal] = button.dataset.corner!;
const side = horizontal === 'l' ? 'left' : 'right';
const edge = vertical === 't' ? 'top' : 'bottom';
popup.dataset.side = side;
popup.dataset.edge = edge;
popup.style.setProperty('--anchor-origin', `${side} ${edge}`);
popup.dataset.open = 'true';
popup.setAttribute('aria-hidden', 'false');
popup.textContent = `Opened from ${edge} ${side}`;
button.setAttribute('aria-expanded', 'true');
trigger = button;
});
}
stage.querySelector<HTMLInputElement>('.pop-mode input')!.addEventListener('change', (event) => {
stage.dataset.naive = String((event.target as HTMLInputElement).checked);
});
document.addEventListener('pointerdown', (event) => {
if (!stage.contains(event.target as Node)) closePopover();
});
stage.addEventListener('keydown', (event) => {
if (event.key === 'Escape') closePopover(true);
});Anchor a popover to each trigger. Derive transform-origin from its corner. Transition opacity and scale from .95, close with Escape and outside clicks, and restore focus on keyboard dismissal.Blur-masked state morph
Save to see Idle, Saving, and Saved in one stable button.
Code & AI prompt
.morph-stage { align-content: center; gap: 10px; }
.morph-button { display: grid; min-width: 130px; }
.morph-button span { grid-area: 1/1; opacity: 0; filter: blur(2px); transform: translateY(3px); transition: opacity 140ms, filter 160ms, transform 160ms var(--ease-out); }
.morph-button[data-state="idle"] [data-label="idle"],
.morph-button[data-state="saving"] [data-label="saving"],
.morph-button[data-state="saved"] [data-label="saved"] { opacity: 1; filter: blur(0); transform: translateY(0); }
.morph-button[data-state="saved"] { background: #0759b4; }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .001ms;
transition-duration: .001ms;
}
}const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const morph = document.querySelector<HTMLButtonElement>('.morph-button')!;
const status = document.querySelector<HTMLElement>('#morph-status')!;
function setMorph(state: string, label: string) {
morph.dataset.state = state;
morph.setAttribute('aria-label', label);
status.textContent = state === 'idle' ? 'Ready to save' : label;
}
morph.addEventListener('click', () => {
if (morph.dataset.state !== 'idle') return;
morph.setAttribute('aria-busy', 'true');
setMorph('saving', 'Saving…');
setTimeout(() => {
morph.removeAttribute('aria-busy');
setMorph('saved', 'Saved ✓');
}, 640);
setTimeout(() => setMorph('idle', 'Save changes'), 2000);
});Layer three labels in one fixed-size grid cell. Crossfade opacity with blur(2px) and minimal travel. Expose saving and saved states to assistive technologies and guard against duplicate submissions.Clip-path tabs and hold-to-delete
Switch tabs, then hold Delete for two seconds. Release to cancel.
Hold for two seconds.
Code & AI prompt
.segmented-stage { align-content: center; gap: 11px; }
.clip-tabs { position: relative; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); border-radius: 8px; background: var(--canvas); border: 1px solid var(--line); }
.clip-tabs button,.clip-tabs-overlay span { min-width: 0; min-height: 38px; display: grid; place-items: center; padding: 5px 7px; border: 0; background: none; color: inherit; font-size: .78rem; position: relative; }
.clip-tabs button:focus-visible { z-index: 2; }
.clip-tabs-overlay {
pointer-events: none; position: absolute; inset: 0; display: grid; grid-template-columns: repeat(3,minmax(0,1fr));
grid-column: 1/-1; background: var(--ink); color: var(--canvas);
clip-path: inset(0 var(--clip-right,66.666%) 0 var(--clip-left,0%) round 7px);
transition: clip-path 200ms var(--ease-in-out);
}
.hold-delete { isolation: isolate; overflow: hidden; position: relative; }
.hold-delete::before { position: absolute; inset: 0; content: ''; z-index: -1; background: var(--error-soft); transform: scaleX(var(--hold-progress, 0)); transform-origin: left; transition: transform 200ms var(--ease-out); }
.hold-delete[data-hold="true"]::before { transform: scaleX(1); transition: transform 2s linear; }
.hold-delete[data-deleted="true"] { color: var(--error); }
.hold-delete span { min-width: 11ch; }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .001ms;
transition-duration: .001ms;
}
}const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const tabs = document.querySelector<HTMLElement>('.clip-tabs')!;
const tabButtons = [...tabs.querySelectorAll<HTMLButtonElement>('button')];
const tabPreview = document.querySelector<HTMLElement>('#segment-content')!;
function chooseTab(index: number) {
tabButtons.forEach((button, n) => {
button.setAttribute('aria-selected', String(n === index));
button.tabIndex = n === index ? 0 : -1;
});
tabs.style.setProperty('--clip-left', `${index * 100 / 3}%`);
tabs.style.setProperty('--clip-right', `${(2 - index) * 100 / 3}%`);
tabPreview.setAttribute('aria-labelledby', tabButtons[index].id);
tabPreview.textContent = `${tabButtons[index].textContent} selected`;
}
tabButtons.forEach((button, index) => {
button.addEventListener('click', () => chooseTab(index));
button.addEventListener('keydown', (event) => {
if (!['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(event.key)) return;
event.preventDefault();
const next = { ArrowRight: (index + 1) % 3, ArrowLeft: (index + 2) % 3, Home: 0, End: 2 }[event.key]!;
chooseTab(next);
tabButtons[next].focus();
});
});
const hold = document.querySelector<HTMLButtonElement>('.hold-delete')!;
const holdLabel = hold.querySelector('span')!;
let heldAt = 0;
let holdTimer = 0;
let holdPointer: number | undefined;
function cancelHold() {
clearTimeout(holdTimer);
if (heldAt) {
const progress = Math.min((performance.now() - heldAt) / 2000, 1);
hold.style.setProperty('--hold-progress', String(progress));
hold.dataset.hold = 'false';
hold.getBoundingClientRect();
hold.style.setProperty('--hold-progress', '0');
}
heldAt = 0;
holdPointer = undefined;
}
function startHold() {
if (heldAt || hold.dataset.deleted === 'true') return;
heldAt = performance.now();
hold.dataset.hold = 'true';
holdTimer = window.setTimeout(() => {
cancelHold();
hold.dataset.deleted = 'true';
holdLabel.textContent = 'Reset item';
document.querySelector('#hold-status')!.textContent = 'Demo item deleted.';
}, 2000);
}
hold.addEventListener('pointerdown', (event) => {
if (event.button !== 0) return;
if (hold.dataset.deleted === 'true') return;
holdPointer = event.pointerId;
hold.setPointerCapture(event.pointerId);
startHold();
});
hold.addEventListener('pointerup', (event) => {
if (holdPointer === event.pointerId) {
event.preventDefault();
cancelHold();
}
});
let resetAllowed = false;
hold.addEventListener('pointerdown', () => { resetAllowed = hold.dataset.deleted === 'true'; });
hold.addEventListener('pointercancel', cancelHold);
hold.addEventListener('lostpointercapture', cancelHold);
hold.addEventListener('blur', cancelHold);
hold.addEventListener('keydown', (event) => {
if (event.key === 'Escape') cancelHold();
if ([' ', 'Enter'].includes(event.key) && hold.dataset.deleted !== 'true') {
event.preventDefault();
if (!event.repeat) startHold();
}
});
hold.addEventListener('keyup', (event) => {
if ([' ', 'Enter'].includes(event.key) && heldAt) {
event.preventDefault();
cancelHold();
}
});
hold.addEventListener('click', (event) => {
if (hold.dataset.deleted === 'true' && (resetAllowed || event.detail === 0)) {
hold.dataset.deleted = 'false';
holdLabel.textContent = 'Hold to delete';
document.querySelector('#hold-status')!.textContent = 'Demo item restored.';
}
});Clip a duplicate tab label track to the active item. Support arrow keys and visible focus. Require two seconds of pointer or keyboard hold, reverse the fill in 200ms on cancellation, and provide an accessible reset.Interruptible stacked toasts
Spawn several toasts, then hover or focus the stack to expand.
Code & AI prompt
.toast-stage { grid-template-rows: 1fr auto; gap: 7px; min-height: 158px; }
.toast-stack { position: relative; width: min(260px,100%); height: 124px; }
.toast-item {
display: flex; justify-content: space-between; align-items: center; gap: 6px;
position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 7px 2px 10px;
background: var(--canvas); border-radius: 8px; box-shadow: var(--shadow);
transform: translateY(calc(var(--layer) * -7px)) scale(calc(1 - var(--layer) * .045));
transition: transform 300ms var(--ease-out), opacity 220ms var(--ease-out);
font-size: .82rem;
}
.toast-item[data-leaving] { transform: translateY(14px) scale(.95); opacity: 0; pointer-events: none; }
@starting-style { .toast-item { transform: translateY(12px) scale(.95); opacity: 0; } }
.toast-stack:focus-within .toast-item { transform: translateY(calc(var(--layer) * -39px)); }
@media (hover: hover) and (pointer: fine) {
.toast-stack:hover .toast-item { transform: translateY(calc(var(--layer) * -39px)); }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .001ms;
transition-duration: .001ms;
}
}const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const stack = document.querySelector<HTMLElement>('.toast-stack')!;
const spawn = document.querySelector<HTMLButtonElement>('[data-spawn-toast]')!;
let toastCount = 0;
const liveToasts: HTMLElement[] = [];
function layoutToasts() {
liveToasts.forEach((toast, i) => {
toast.style.setProperty('--layer', String(i));
toast.style.zIndex = String(4 - i);
});
}
function dismissToast(toast: HTMLElement) {
const index = liveToasts.indexOf(toast);
if (index < 0) return;
liveToasts.splice(index, 1);
if (toast.contains(document.activeElement)) spawn.focus();
toast.dataset.leaving = '';
toast.inert = true;
layoutToasts();
setTimeout(() => toast.remove(), 300);
}
spawn.addEventListener('click', () => {
const toast = document.createElement('div');
toast.className = 'toast-item';
const label = document.createElement('span');
label.textContent = `Update ${++toastCount} saved`;
label.setAttribute('role', 'status');
const dismiss = document.createElement('button');
dismiss.className = 'button compact';
dismiss.type = 'button';
dismiss.textContent = 'Dismiss';
dismiss.setAttribute('aria-label', `Dismiss update ${toastCount}`);
dismiss.addEventListener('click', () => dismissToast(toast));
toast.append(label, dismiss);
stack.prepend(toast);
liveToasts.unshift(toast);
if (liveToasts.length > 3) dismissToast(liveToasts.at(-1)!);
layoutToasts();
setTimeout(() => {
if (!stack.matches(':hover,:focus-within')) dismissToast(toast);
}, 6000);
});Stack at most three visible toasts with translate and scale. Use interruptible transitions for stacking, expansion, and dismissal. Keep dismiss buttons keyboard-accessible and announce each update.Spring curve playground
Drag the ball or tap Move to see the ball and card follow the same spring.
Code & AI prompt
.spring-stage { padding: 10px; display: grid; gap: 7px; }
.spring-rail { position: relative; height: 70px; overflow: hidden; border: 1px solid var(--line); background: var(--canvas); border-radius: 8px; }
.spring-rail::before { content: ''; position: absolute; left: 12px; right: 12px; top: 20px; border-top: 1px dashed var(--line-strong); }
.spring-ball { position: absolute; top: 6px; left: 5px; width: 28px; height: 28px; background: var(--ink); color: var(--canvas); border: 0; border-radius: 50%; touch-action: none; cursor: grab; transform: translateX(var(--spring-x,0px)); }
.spring-ball:active { cursor: grabbing; transform: translateX(var(--spring-x,0px)) scale(.97); }
.spring-card { position: absolute; top: 38px; left: 5px; display: grid; place-items: center; width: 66px; height: 24px; border: 1px solid var(--line); border-radius: 5px; background: var(--canvas-inset); color: var(--body); font: 500 .64rem var(--mono); transform: translateX(var(--spring-x,0px)); }
@media (prefers-reduced-motion: reduce) {
.spring-ball:active { transform: translateX(var(--spring-x,0px)); }
}
.spring-curve { display: block; width: 100%; height: 43px; background: var(--canvas); border-radius: 6px; }
.spring-curve path { fill: none; stroke: var(--link); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spring-status { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.spring-status output { font: 500 .69rem var(--mono); color: var(--body); }
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: .001ms;
transition-duration: .001ms;
}
}const reduced = matchMedia('(prefers-reduced-motion: reduce)');
const spring = document.querySelector<HTMLElement>('.spring-stage')!;
const rail = spring.querySelector<HTMLElement>('.spring-rail')!;
const ball = spring.querySelector<HTMLButtonElement>('.spring-ball')!;
const curve = spring.querySelector<SVGPathElement>('.spring-curve path')!;
const springOutput = spring.querySelector<HTMLOutputElement>('.spring-status output')!;
const springInputs = [...spring.querySelectorAll<HTMLInputElement>('input')];
function parameters() {
const [stiffness, damping, mass] = springInputs.map((input) => Number(input.value));
return { stiffness, damping, mass };
}
function drawCurve() {
const { stiffness, damping, mass } = parameters();
let x = 0;
let velocity = 0;
let d = 'M 0 48';
for (let i = 1; i <= 150; i++) {
const acceleration = (stiffness * (1 - x) - damping * velocity) / mass;
velocity += acceleration * .008;
x += velocity * .008;
d += ` L ${i * 2} ${48 - 31 * x}`;
}
curve.setAttribute('d', d);
springOutput.value = `ζ ${(damping / (2 * Math.sqrt(stiffness * mass))).toFixed(2)}`;
}
let position = 0;
let speed = 0;
let target = 0;
let frame = 0;
let dragStart: number | undefined;
let moved = false;
function renderBall() {
rail.style.setProperty('--spring-x', `${position * Math.max(0, rail.clientWidth - 77)}px`);
}
function moveBall(next: number) {
target = next;
cancelAnimationFrame(frame);
if (reduced.matches) {
position = target;
speed = 0;
renderBall();
return;
}
let last = performance.now();
function tick(now: number) {
const { stiffness, damping, mass } = parameters();
const step = Math.min((now - last) / 1000, .032) / 4;
last = now;
for (let substep = 0; substep < 4; substep++) {
speed += ((stiffness * (target - position) - damping * speed) / mass) * step;
position += speed * step;
}
if (Math.abs(target - position) > .001 || Math.abs(speed) > .004) {
frame = requestAnimationFrame(tick);
} else {
position = target;
speed = 0;
}
renderBall();
}
frame = requestAnimationFrame(tick);
}
const toggleBall = () => moveBall(target > .5 ? .05 : .85);
ball.addEventListener('pointerdown', (event) => {
ball.setPointerCapture(event.pointerId);
dragStart = event.clientX;
moved = false;
cancelAnimationFrame(frame);
});
ball.addEventListener('pointermove', (event) => {
if (dragStart === undefined || (!moved && Math.abs(event.clientX - dragStart) < 3)) return;
moved = true;
position = Math.max(0, Math.min(1, (event.clientX - rail.getBoundingClientRect().left - 19) / (rail.clientWidth - 77)));
target = position;
speed = 0;
renderBall();
});
ball.addEventListener('lostpointercapture', () => { dragStart = undefined; });
ball.addEventListener('click', (event) => { if (!moved || event.detail === 0) toggleBall(); });
spring.querySelector('[data-move-ball]')!.addEventListener('click', toggleBall);
spring.addEventListener('input', (event) => {
const input = event.target as HTMLInputElement;
input.closest('label')!.querySelector('output')!.value = input.value;
drawCurve();
moveBall(target > .5 ? .05 : .85);
});
new ResizeObserver(renderBall).observe(rail);
drawCurve();Use a damped spring equation with capped integration steps. Make the ball draggable, drive the card with the same spring, and add a keyboard-operable Move action. Draw the measured spring response and settle immediately in reduced motion.