Snap guide — equal spacing
Variant: Spacing
A box dragged between two neighbours while both gaps count toward each other — 4 against 48, then 20 against 32 — and caught 6px from equal, where both read 26. The readouts are live the whole way because spacing is the one alignment nobody can eyeball: an edge guide can be judged by sight, two gaps a few pixels apart cannot, so the numbers are the steering. The drag is deliberately slow, 1.2s for 16px, the pace of someone reading the counters and correcting by them, and it reaches the catch still moving so the snap reads as the last of the drag rather than a second event. Agreement is a state, not a degree: both rules and both badges take the accent on the snap’s first frame rather than warming up through it. Each badge rides half the object’s travel, because that is how far a gap’s midpoint moves. For distribute-evenly in design tools, dashboard builders and slide editors.
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>Snap guide — equal spacing</title>
<style>
/* One registered number is the offset from equal spacing; both gap
lines, both badges and the object read it, so the two readouts
cannot disagree with the geometry by a frame. The integers ride the
same keyframes on the same curve for the counters. */
@property --_o {
syntax: '<number>';
inherits: true;
initial-value: -22;
}
@property --_gl {
syntax: '<integer>';
inherits: true;
initial-value: 4;
}
@property --_gr {
syntax: '<integer>';
inherits: true;
initial-value: 48;
}
: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 — 3.6s: one careful drag with the gaps counting toward each
other, a catch at 6px, the drop. */
--cycle: 3.6s;
--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);
/* The snap — the same 78ms catch as the rest of the family. */
--ease-accent: cubic-bezier(0.32, 0.72, 0, 1);
/* Approach: leaves rest but reaches the threshold still moving, so
the snap carries the drag on instead of firing after a stop. */
--_approach: cubic-bezier(0.55, 0, 0.75, 0.75);
--_muted: color-mix(in srgb, var(--slate) 52%, transparent);
--_bar: color-mix(in srgb, var(--oat) 80%, transparent);
--_rule: color-mix(in srgb, var(--slate) 34%, transparent);
}
* {
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);
}
.rig {
display: grid;
gap: 12px;
justify-items: center;
animation: rig var(--t) linear infinite;
}
.cap,
.foot {
font-size: 11px;
letter-spacing: 0.03em;
color: var(--_muted);
}
.stage {
position: relative;
width: 260px;
height: 150px;
background: var(--paper);
border: 1px solid var(--oat);
border-radius: calc(10px * var(--round));
overflow: hidden;
animation: offset var(--t) infinite;
}
.obj {
position: absolute;
top: 40px;
width: 56px;
height: 56px;
padding: 10px;
display: grid;
align-content: center;
gap: 6px;
background: var(--paper);
border: 1px solid var(--oat);
border-radius: calc(5px * var(--round));
}
.obj i {
display: block;
height: 5px;
border-radius: 999px;
background: var(--_bar);
}
.obj i + i {
width: 60%;
}
.l {
left: 20px;
}
.r {
left: 184px;
}
/* Offsets are measured from equal spacing: at 0 both gaps are 26. */
.m {
left: 102px;
border: 1.5px solid var(--slate);
transform: translateX(calc(var(--_o) * 1px));
}
/* Gap rules scale from the edge they are anchored to, so each one is
always exactly the gap it measures. */
.rule {
position: absolute;
top: 67.5px;
width: 26px;
height: 1px;
background: var(--_rule);
animation: agree-bg var(--t) linear infinite;
}
.rule.gl {
left: 76px;
transform-origin: left center;
transform: scaleX(calc((26 + var(--_o)) / 26));
}
.rule.gr {
left: 158px;
transform-origin: right center;
transform: scaleX(calc((26 - var(--_o)) / 26));
}
.badge {
position: absolute;
top: 108px;
padding: 1px 5px;
border-radius: calc(4px * var(--round));
font-size: 11px;
font-weight: 600;
line-height: 16px;
font-variant-numeric: tabular-nums;
background: var(--oat);
color: var(--slate);
animation: agree-badge var(--t) linear infinite;
}
/* Each badge sits under its gap's centre, which moves half as far as
the object does. */
.badge.gl {
left: 89px;
transform: translateX(calc(-50% + var(--_o) * 0.5px));
}
.badge.gl::before {
counter-reset: g var(--_gl);
content: counter(g);
}
.badge.gr {
left: 171px;
transform: translateX(calc(-50% + var(--_o) * 0.5px));
}
.badge.gr::before {
counter-reset: g var(--_gr);
content: counter(g);
}
.hand {
position: absolute;
inset: 0;
animation: hand var(--t) infinite;
}
.ptr {
position: absolute;
left: 129px;
top: 67px;
width: 14px;
height: 18px;
opacity: 0;
animation: ptr var(--t) linear infinite;
}
.arrow {
display: block;
width: 100%;
height: 100%;
fill: var(--slate);
stroke: var(--paper);
stroke-width: 1.4;
stroke-linejoin: round;
}
.tip {
position: absolute;
left: -9px;
top: -9px;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--clay-d);
opacity: 0;
transform: scale(0.5);
animation: grip var(--t) infinite;
}
/* The drag is slow on purpose: 1.2s for 16px, the pace of someone
reading the two numbers and steering by them. */
@keyframes offset {
0%,
6% {
--_o: -22;
--_gl: 4;
--_gr: 48;
animation-timing-function: var(--_approach);
}
40% {
--_o: -6;
--_gl: 20;
--_gr: 32;
animation-timing-function: var(--ease-accent);
}
42.2%,
94% {
--_o: 0;
--_gl: 26;
--_gr: 26;
}
94.1%,
100% {
--_o: -22;
--_gl: 4;
--_gr: 48;
}
}
@keyframes hand {
0%,
6% {
transform: translate(-22px, 0);
animation-timing-function: var(--_approach);
}
40% {
transform: translate(-6px, 0);
animation-timing-function: var(--ease-out);
}
46% {
transform: translate(-3px, 0);
animation-timing-function: var(--ease-out);
}
58%,
94% {
transform: translate(12px, 22px);
}
94.1%,
100% {
transform: translate(-22px, 0);
}
}
/* Agreement is a state, not a degree: both rules and both badges take
the accent on the snap's first frame, never partway through it. */
@keyframes agree-bg {
0%,
40% {
background: var(--_rule);
}
40.5%,
100% {
background: var(--clay-d);
}
}
@keyframes agree-badge {
0%,
40% {
background: var(--oat);
color: var(--slate);
}
40.5%,
100% {
background: var(--clay-d);
color: var(--paper);
}
}
@keyframes ptr {
0% {
opacity: 0;
}
5%,
46% {
opacity: 1;
}
56%,
100% {
opacity: 0;
}
}
@keyframes grip {
0%,
5.5% {
opacity: 0;
transform: scale(0.5);
animation-timing-function: var(--ease-out);
}
6%,
45.5% {
opacity: 0.4;
transform: scale(1);
animation-timing-function: var(--ease-out);
}
46.5%,
100% {
opacity: 0;
transform: scale(0.5);
}
}
@keyframes rig {
0% {
opacity: 0;
}
3%,
88% {
opacity: 1;
}
93%,
100% {
opacity: 0;
}
}
@media (prefers-reduced-motion: reduce) {
/* The object rests at equal spacing; the two agreeing badges breathe
together, which is the whole claim without the travel. */
.rig,
.stage,
.hand {
animation: none;
}
.stage {
--_o: 0;
--_gl: 26;
--_gr: 26;
}
.hand {
opacity: 0;
}
.rule {
animation: none;
background: var(--clay-d);
}
.badge {
background: var(--clay-d);
color: var(--paper);
animation: badge-rest calc(var(--t) * 1.2) ease-in-out infinite;
}
@keyframes badge-rest {
0%,
100% {
opacity: 0.55;
}
50% {
opacity: 1;
}
}
}
</style>
</head>
<body>
<div
class="rig"
role="img"
aria-label="A box is dragged between two neighbours while the two gap measurements count toward each other, four and forty-eight; within six pixels of equal it snaps to the middle and both gaps read twenty-six in the accent colour."
>
<p class="cap">drag · count · agree</p>
<div class="stage">
<div class="obj l"><i></i><i></i></div>
<div class="obj r"><i></i><i></i></div>
<i class="rule gl"></i>
<i class="rule gr"></i>
<div class="obj m"><i></i><i></i></div>
<span class="badge gl"></span>
<span class="badge gr"></span>
<div class="hand">
<span class="ptr">
<span class="tip"></span>
<svg class="arrow" viewBox="0 0 14 18">
<path d="M1 1 L1 14.8 L4.5 11.6 L6.7 16.6 L9.3 15.4 L7.1 10.5 L11.8 10.3 Z" />
</svg>
</span>
</div>
</div>
<p class="foot">the gaps read live · the snap is when they agree</p>
</div>
</body>
</html>
The variant family
Same idea, one axis moved. Compare them side by side before you commit.