# Patterns
The parts every page repeats, written to pass the gates. Take the code's shape; the names, copy, values and composition are yours. `tokens.css`, `base.css` and the slot script come from the scaffold.
## Controls, all eight states
```css
.btn { display: inline-flex; align-items: center; gap: var(--space-xs); min-height: 48px; padding: 0 var(--space-lg); border: 1px solid var(--color-ink); border-radius: var(--radius-input, var(--radius-pill)); background: var(--color-ink); color: var(--color-paper); font: 500 var(--text-md)/1 var(--font-body); white-space: nowrap; text-decoration: none; cursor: pointer; transition: background-color var(--dur-short) var(--ease-out), transform var(--dur-micro) var(--ease-out); }
.btn:hover { background: var(--color-ink-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { cursor: progress; }
.btn--quiet { background: transparent; color: var(--color-ink); border-color: var(--color-rule); }
.btn--quiet:hover { background: var(--color-paper-2); }
@media (prefers-reduced-motion: reduce) { .btn { transition: background-color var(--dur-short) linear; } }
```
One filled primary a page (F4); the quiet one goes somewhere else. Error and success belong to the form, below.
## A photograph in a slot
```html
Picking runs from September to the first frost.
``` ```css .photo { aspect-ratio: 4 / 5; min-height: 440px; margin: 0; border-radius: var(--radius-card); } .photo > img { outline: 1px solid color-mix(in oklab, var(--color-ink) 8%, transparent); outline-offset: -1px; } .caption { margin-top: var(--space-sm); font-size: var(--text-sm); color: var(--color-ink-2); } ``` The `Doors at time to be announced, at the venue.
``` ```css .fill { padding: 0 0.25em; border: 1px dashed color-mix(in oklch, var(--color-muted) 70%, transparent); border-radius: 3px; color: var(--color-muted); -webkit-box-decoration-break: clone; box-decoration-break: clone; } ``` Two a page at most, each named in the handoff (`craft.md` § 8). ## A form that posts nowhere yet ```html ``` ```js document.querySelectorAll('form[data-endpoint]').forEach((form) => { const input = form.querySelector('input'), help = form.querySelector('[aria-live]'); form.addEventListener('submit', (e) => { e.preventDefault(); const ok = input.checkValidity(); input.toggleAttribute('aria-invalid', !ok); if (!ok) { input.setAttribute('aria-describedby', help.id); help.textContent = 'That address looks incomplete. Write it as name@example.com.'; input.focus(); return; } if (!form.dataset.endpoint) { help.textContent = 'Nothing was sent: this form is not connected yet.'; return; } fetch(form.dataset.endpoint, { method: 'POST', body: new FormData(form) }) .then((r) => { help.textContent = r.ok ? 'Thanks. The date goes to ' + input.value.trim() + '.' : 'That did not go through. Try again in a minute.'; }) .catch(() => { help.textContent = 'That did not go through. Try again in a minute.'; }); }); }); ``` ```css .signup__row { display: flex; gap: var(--space-xs); } .signup input { flex: 1; min-width: 0; min-height: 48px; padding: 0 var(--space-md); border: 1px solid var(--color-muted); border-radius: var(--radius-input, var(--radius-pill)); background: var(--color-paper); color: var(--color-ink); outline: 2px solid transparent; outline-offset: -3px; } .signup input:focus-visible { outline-color: var(--color-focus); } .signup input[aria-invalid] { border-color: var(--color-error); } .signup__help { min-height: 1lh; margin-top: var(--space-2xs); font-size: var(--text-sm); color: var(--color-muted); } ``` ## One reveal that survives no script ```html ``` ```css .js [data-reveal] { opacity: 0; transform: translateY(8px); transition: opacity var(--dur-long) var(--ease-out), transform var(--dur-long) var(--ease-out); transition-delay: calc(var(--i, 0) * 40ms); } .js [data-reveal].is-in { opacity: 1; transform: none; } @media (prefers-reduced-motion: reduce) { .js [data-reveal] { opacity: 1; transform: none; transition: none; } } ``` ```js const io = new IntersectionObserver((es) => es.forEach((e) => { if (e.isIntersecting) { e.target.classList.add('is-in'); io.unobserve(e.target); } }), { rootMargin: '0px 0px -10% 0px' }); document.querySelectorAll('[data-reveal]').forEach((el) => io.observe(el)); ``` Visible with scripting off (62), at its end state under reduced motion, once, and only where the theme lets something move. ## Figures that compare ```css .stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); } .stats > * { padding-inline: var(--space-lg); border-left: 1px solid var(--color-rule); } .stats > :first-child { padding-left: 0; border-left: 0; } .stats b { display: block; font: 600 var(--text-3xl)/1 var(--font-display); font-variant-numeric: tabular-nums; } @media (max-width: 60rem) { .stats { grid-template-columns: minmax(0, 1fr); } .stats > * { padding: var(--space-md) 0; border-left: 0; border-top: 1px solid var(--color-rule); } .stats > :first-child { border-top: 0; } } ``` Only figures the user gave (46a), each with its unit and what it counts. ## A loop that can pause Anything moving past 5 seconds (a marquee, an ambient loop, a looping video) holds still until the script runs, stops off-screen and under reduced motion, pauses on hover and focus, and carries a visible pause control (18, WCAG 2.2.2). ```html