Affinity — collapse to count
Variant: Collapse to count
A theme folded away into its header, where the rows become the number. The rows slide up under an opaque header, each with a travel time proportional to its distance: 22, 48 and 74px in 148, 322 and 496ms. All three keep one pace and land in order, about 170ms apart. The count pill is fully in by the time the first one lands. It reads 1, 2, 3 as hard cuts, each on the frame a row lands, so the count is visibly made of the rows rather than announced beside them. Each row shrinks 6% toward the header it is going under, never toward its own centre. The section below rides the last row’s clock and curve as if attached to it, so it never waits on an empty gap and never overtakes. Collapse is ease-in-out, because the rows travel to a place that exists. Expand is ease-out, because they are entering, and the pill gives itself up at once on the way out, because when the rows are on screen they are the count. Under reduced motion the rows fade in place on the same landing frames, so the count still ticks. Reach for it on collapsible sections, grouped notifications and filter facets, anywhere a summary number replaces content the user just watched leave.
The source
A complete HTML document. Paste it into an empty .html file and it plays — no stylesheet, script, font, or image to fetch.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Affinity — collapse to count</title>
<style>
:root {
/* Neutrals — fixed, never remixed. */
--ivory: #faf9f5;
--paper: #ffffff;
--oat: #e3dacc;
--slate: #141413;
/* Knobs — the remix API. A knob exists iff declared here and used below. */
--hue: 38.8;
--lift: 0;
--chroma: 1;
--round: 1;
--speed: 1;
/* Accents — derived from the knobs with the family's offsets baked in,
so one hue roll moves them together. Defaults reproduce the original hex. */
--clay: oklch(calc(0.6724 + var(--lift)) calc(0.1308 * var(--chroma)) var(--hue));
--clay-d: oklch(calc(0.5797 + var(--lift)) calc(0.127 * var(--chroma)) var(--hue));
--olive: oklch(
calc(0.6118 + var(--lift)) calc(0.0713 * var(--chroma)) calc(var(--hue) + 88.3)
);
--rust: oklch(
calc(0.5408 + var(--lift)) calc(0.1357 * var(--chroma)) calc(var(--hue) - 10.3)
);
/* Clock — 6.4s. Each row's travel time is proportional to its distance
from the header (22 / 48 / 74px in 148 / 322 / 496ms), so all three
keep one pace and land in order, ~170ms apart; the count is written
by those landings. */
--cycle: 6.4s;
--t: calc(var(--cycle) / var(--speed));
--ease-out: cubic-bezier(0.23, 1, 0.32, 1);
--ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
/* Row pitch — row plus gap. */
--_p: 26px;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
min-height: 100vh;
display: grid;
place-items: center;
background: var(--ivory);
font-family:
system-ui,
-apple-system,
'Segoe UI',
Roboto,
sans-serif;
color: var(--slate);
}
.board {
position: relative;
width: min(248px, 86vw);
height: 176px;
}
.hdr {
position: absolute;
left: 0;
right: 0;
height: 22px;
padding-left: 2px;
display: flex;
align-items: center;
gap: 6px;
font-size: 11px;
font-weight: 600;
letter-spacing: 0.02em;
color: color-mix(in srgb, var(--slate) 62%, transparent);
}
/* The header is opaque and on top: rows are gathered under it, not
faded in front of it. */
.h-exp {
top: 0;
z-index: 5;
background: var(--ivory);
}
.chev {
flex: none;
width: 10px;
height: 10px;
margin-right: -1px;
animation: chev var(--t) infinite;
}
.chev.still {
animation: none;
}
.dot {
flex: none;
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--clay);
}
.o .dot,
.h-onb .dot {
background: var(--olive);
}
/* The count pill only exists while the rows it counts are hidden: when
they are on screen, they are the count. */
.pill {
position: relative;
display: inline-block;
min-width: 19px;
height: 15px;
border-radius: 999px;
background: color-mix(in srgb, var(--oat) 80%, var(--paper));
font-size: 11px;
font-weight: 600;
line-height: 15px;
text-align: center;
font-variant-numeric: tabular-nums;
color: color-mix(in srgb, var(--slate) 72%, transparent);
opacity: 0;
animation: pill var(--t) infinite;
}
.pill span {
position: absolute;
inset: 0;
opacity: 0;
animation-timing-function: linear;
}
.d1 {
animation: d1 var(--t) infinite;
}
.d2 {
animation: d2 var(--t) infinite;
}
.d3 {
animation: d3 var(--t) infinite;
}
.row {
position: absolute;
left: 0;
right: 0;
height: 22px;
display: flex;
align-items: center;
gap: 7px;
padding: 0 8px;
font-size: 12px;
white-space: nowrap;
background: var(--paper);
border: 1px solid color-mix(in srgb, var(--slate) 10%, transparent);
border-radius: calc(5px * var(--round));
box-shadow: 0 0 0 2px var(--ivory);
transform-origin: top;
}
.r1 {
top: 22px;
z-index: 3;
--_dy: -22px;
animation: r1 var(--t) infinite;
}
.r2 {
top: calc(22px + var(--_p));
z-index: 2;
--_dy: calc(-22px - var(--_p));
animation: r2 var(--t) infinite;
}
.r3 {
top: calc(22px + 2 * var(--_p));
z-index: 1;
--_dy: calc(-22px - 2 * var(--_p));
animation: r3 var(--t) infinite;
}
/* The section below rides the last row's clock and curve, so it moves
as if attached to it: never waiting on an empty gap, never
overtaking the row it follows. */
.below {
position: absolute;
inset: 0;
animation: below var(--t) infinite;
}
.h-onb {
top: calc(4 * var(--_p) + 2px);
}
.o1 {
top: calc(22px + 4 * var(--_p) + 2px);
}
.o2 {
top: calc(22px + 5 * var(--_p) + 2px);
}
/* Collapse: on-screen travel to a place that exists, so ease-in-out;
opacity goes only in the last part, under the header.
Expand: the rows enter, so ease-out, and they are visible at once. */
@keyframes r1 {
0%,
14% {
translate: 0 0;
scale: 1;
opacity: 1;
animation-timing-function: var(--ease-in-out);
}
15.3% {
opacity: 1;
animation-timing-function: linear;
}
16.3125%,
58% {
translate: 0 var(--_dy);
scale: 0.94;
opacity: 0;
animation-timing-function: var(--ease-out);
}
59.3% {
opacity: 1;
}
60.3125%,
100% {
translate: 0 0;
scale: 1;
opacity: 1;
}
}
@keyframes r2 {
0%,
14% {
translate: 0 0;
scale: 1;
opacity: 1;
animation-timing-function: var(--ease-in-out);
}
17.6% {
opacity: 1;
animation-timing-function: linear;
}
19.03125%,
58% {
translate: 0 var(--_dy);
scale: 0.94;
opacity: 0;
animation-timing-function: var(--ease-out);
}
59.6% {
opacity: 1;
}
63.03125%,
100% {
translate: 0 0;
scale: 1;
opacity: 1;
}
}
@keyframes r3 {
0%,
14% {
translate: 0 0;
scale: 1;
opacity: 1;
animation-timing-function: var(--ease-in-out);
}
20.2% {
opacity: 1;
animation-timing-function: linear;
}
21.75%,
58% {
translate: 0 var(--_dy);
scale: 0.94;
opacity: 0;
animation-timing-function: var(--ease-out);
}
59.9% {
opacity: 1;
}
65.75%,
100% {
translate: 0 0;
scale: 1;
opacity: 1;
}
}
@keyframes below {
0%,
14% {
translate: 0 0;
animation-timing-function: var(--ease-in-out);
}
21.75%,
58% {
translate: 0 calc(-3 * var(--_p) + 2px);
animation-timing-function: var(--ease-out);
}
65.75%,
100% {
translate: 0 0;
}
}
@keyframes chev {
0%,
14% {
rotate: 0deg;
animation-timing-function: var(--ease-in-out);
}
17.75%,
58% {
rotate: -90deg;
animation-timing-function: var(--ease-in-out);
}
61.75%,
100% {
rotate: 0deg;
}
}
/* The pill is fully in on the frame the first row lands, already
reading 1, and gives itself up at once on expand — the rows are about
to be countable again. */
@keyframes pill {
0%,
15.6% {
opacity: 0;
scale: 0.9;
animation-timing-function: var(--ease-out);
}
16.3125%,
58% {
opacity: 1;
scale: 1;
animation-timing-function: var(--ease-out);
}
59.5%,
100% {
opacity: 0;
scale: 1;
}
}
/* Digits are cuts, not fades: each changes on the frame a row lands. */
@keyframes d1 {
0%,
15.59% {
opacity: 0;
}
15.60%,
19.02% {
opacity: 1;
}
19.03%,
100% {
opacity: 0;
}
}
@keyframes d2 {
0%,
19.02% {
opacity: 0;
}
19.03%,
21.74% {
opacity: 1;
}
21.75%,
100% {
opacity: 0;
}
}
@keyframes d3 {
0%,
21.74% {
opacity: 0;
}
21.75%,
100% {
opacity: 1;
}
}
@media (prefers-reduced-motion: reduce) {
/* No travel: the rows fade where they stand over ~290ms each, in the
same order and landing on the same frames, so the count still ticks
with each one. The section below and the chevron change on a cut. */
.r1,
.r2,
.r3 {
translate: none !important;
scale: none !important;
}
.pill {
scale: none !important;
}
.r1 {
animation-name: rf1;
}
.r2 {
animation-name: rf2;
}
.r3 {
animation-name: rf3;
}
.below {
animation-name: below-step;
}
.chev {
animation-name: chev-step;
}
.r1,
.r2,
.r3,
.below,
.chev,
.pill,
.d1,
.d2,
.d3 {
animation-duration: calc(var(--t) * 1.5);
}
@keyframes rf1 {
0%,
13.31% {
opacity: 1;
animation-timing-function: var(--ease-in-out);
}
16.3125%,
58% {
opacity: 0;
animation-timing-function: var(--ease-out);
}
61%,
100% {
opacity: 1;
}
}
@keyframes rf2 {
0%,
16.03% {
opacity: 1;
animation-timing-function: var(--ease-in-out);
}
19.03125%,
58% {
opacity: 0;
animation-timing-function: var(--ease-out);
}
61%,
100% {
opacity: 1;
}
}
@keyframes rf3 {
0%,
18.75% {
opacity: 1;
animation-timing-function: var(--ease-in-out);
}
21.75%,
58% {
opacity: 0;
animation-timing-function: var(--ease-out);
}
61%,
100% {
opacity: 1;
}
}
@keyframes below-step {
0%,
14% {
translate: 0 0;
animation-timing-function: steps(1, end);
}
21.75%,
58% {
translate: 0 calc(-3 * var(--_p) + 2px);
animation-timing-function: steps(1, start);
}
65.75%,
100% {
translate: 0 0;
}
}
@keyframes chev-step {
0%,
16.3% {
rotate: 0deg;
}
16.31%,
58% {
rotate: -90deg;
}
58.01%,
100% {
rotate: 0deg;
}
}
}
</style>
</head>
<body>
<div
class="board"
role="img"
aria-label="A research theme collapses: its three notes are gathered up under the header one after another, a count pill ticking 1, 2, 3 as each arrives, while the next section rides up behind them; then the group expands again"
>
<div class="hdr h-exp">
<svg class="chev" viewBox="0 0 10 10" aria-hidden="true">
<path
d="M2.5 3.75 5 6.25 7.5 3.75"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<i class="dot"></i>Export
<span class="pill"
><span class="d1">1</span><span class="d2">2</span><span class="d3">3</span></span
>
</div>
<div class="row r1"><i class="dot"></i>Couldn’t find export</div>
<div class="row r2"><i class="dot"></i>Wanted CSV, got PDF</div>
<div class="row r3"><i class="dot"></i>Exported twice to check</div>
<div class="below">
<div class="hdr h-onb">
<svg class="chev still" viewBox="0 0 10 10" aria-hidden="true">
<path
d="M2.5 3.75 5 6.25 7.5 3.75"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<i class="dot"></i>Onboarding
</div>
<div class="row o o1"><i class="dot"></i>Skipped the tour</div>
<div class="row o o2"><i class="dot"></i>Invite step confused</div>
</div>
</div>
</body>
</html>
The variant family
Same idea, one axis moved. Compare them side by side before you commit.