Caret — select by word
Variant: Word select
Extending a selection a word at a time with ⌥⇧→, then backing off a word with ⌥⇧←. The highlight is one band cut back from the right by clip-path on the caret’s own keyframe times and curve, so its moving edge is the caret rather than something chasing it. Every hop is the family’s 96ms glide whether it covers four characters or eleven, because each one is a single keystroke. The stops are the ones editors use: word-left from the end of "opts" lands on its first letter, so the selection shrinks by four rather than back to the previous stop. The anchor gets a quieter second bar for as long as a selection exists — it is the end of a selection nobody can see, yet it decides what every shift-arrow does next. ← collapses the selection to its start: the highlight goes on the keypress frame, one command, while the caret glides home to the anchor. Under reduced motion caret and highlight jump together to each stop. Reach for it for editors and fields that draw their own selection, and for shortcut docs where the gesture is easier shown than described.
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>Caret — select by word</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 — 5.2s. ⌥⇧→ at 14 / 28 / 42%, ⌥⇧← at 62%, ← at 80%. Every
move is the family's 96ms glide (1.85%), whatever its length. The
loop ends where it began, caret at the anchor, so it has no seam. */
--cycle: 5.2s;
--t: calc(var(--cycle) / var(--speed));
--ease-out: cubic-bezier(0.23, 1, 0.32, 1);
--_read: color-mix(in srgb, var(--slate) 80%, transparent);
--_quiet: color-mix(in srgb, var(--slate) 52%, transparent);
--_sel: color-mix(in srgb, var(--clay) 24%, transparent);
--_anchor: color-mix(in srgb, var(--clay-d) 55%, transparent);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
min-height: 100vh;
display: grid;
place-items: center;
padding: clamp(12px, 3vw, 28px);
background: var(--ivory);
color: var(--slate);
font-family:
system-ui,
-apple-system,
'Segoe UI',
Roboto,
sans-serif;
}
.card {
width: min(360px, 92vw);
padding: clamp(15px, 3.6vw, 24px) clamp(16px, 3.8vw, 26px);
border: 1px solid var(--oat);
border-radius: calc(14px * var(--round));
background: var(--paper);
}
.eyebrow {
font-size: clamp(11px, 2.4vw, 12.5px);
font-weight: 600;
letter-spacing: 0.09em;
text-transform: uppercase;
color: var(--_quiet);
}
.code {
position: relative;
margin-top: clamp(10px, 2vw, 15px);
white-space: pre;
font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
font-size: clamp(14px, 4.4vw, 19px);
line-height: 1.7;
color: var(--_read);
isolation: isolate;
}
.code .k {
color: var(--clay-d);
}
/* The selection is a band from the anchor to the farthest stop, cut
back from the right by clip-path. Its keyframes are the caret's
keyframes — same times, same curve — so the moving edge of the
selection is the caret, not something chasing it. */
.sel {
position: absolute;
z-index: -1;
top: 0.16em;
left: 6ch;
width: 15ch;
height: 1.38em;
border-radius: calc(3px * var(--round));
background: var(--_sel);
animation: sel var(--t) infinite;
}
/* The anchor is the half of a selection nobody can see, and the half
that decides what ⌥⇧← will do. It is marked for exactly as long as
a selection exists. */
.anchor {
position: absolute;
top: 0.22em;
left: 6ch;
width: max(2px, 0.09em);
height: 1.26em;
margin-left: -1px;
border-radius: 999px;
background: var(--_anchor);
opacity: 0;
animation: anchor var(--t) infinite;
}
.caret {
position: absolute;
top: 0.22em;
left: 0;
width: max(2px, 0.09em);
height: 1.26em;
margin-left: -1px;
border-radius: 999px;
background: var(--clay);
animation:
caret var(--t) infinite,
blink var(--t) infinite;
}
.via {
display: flex;
align-items: center;
gap: 8px;
margin-top: clamp(12px, 2.6vw, 18px);
font-size: clamp(11px, 2.5vw, 12.5px);
color: var(--_quiet);
}
.slot {
position: relative;
height: 2.6em;
width: 6em;
overflow: hidden;
}
.reel {
display: flex;
flex-direction: column;
animation:
reel var(--t) infinite,
cue var(--t) infinite;
}
.key {
display: inline-flex;
align-items: center;
height: 2.6em;
}
.key b {
padding: 0.12em 0.6em;
border: 1px solid var(--oat);
border-bottom-width: 2px;
border-radius: calc(5px * var(--round));
background: var(--ivory);
font-weight: 500;
color: var(--slate);
}
/* Word stops, not character stops: 6 → 11 → 15 → 21, then back to the
start of "opts" at 17 — word-left lands on a word's first letter, so
the selection shrinks by four, not by six. Fixed 96ms per hop, so a
five-letter word and a six-character jump feel like the same
keystroke, because they are. */
@keyframes caret {
0%,
14% {
transform: translateX(6ch);
animation-timing-function: var(--ease-out);
}
15.85%,
28% {
transform: translateX(11ch);
animation-timing-function: var(--ease-out);
}
29.85%,
42% {
transform: translateX(15ch);
animation-timing-function: var(--ease-out);
}
43.85%,
62% {
transform: translateX(21ch);
animation-timing-function: var(--ease-out);
}
63.85%,
80% {
transform: translateX(17ch);
animation-timing-function: var(--ease-out);
}
81.85%,
100% {
transform: translateX(6ch);
}
}
/* ← with a selection collapses it to its start: the band goes on the
keypress frame, one command, while the caret glides home to the
anchor it was measured from. */
@keyframes sel {
0%,
14% {
clip-path: inset(0 15ch 0 0);
opacity: 1;
animation-timing-function: var(--ease-out);
}
15.85%,
28% {
clip-path: inset(0 10ch 0 0);
opacity: 1;
animation-timing-function: var(--ease-out);
}
29.85%,
42% {
clip-path: inset(0 6ch 0 0);
opacity: 1;
animation-timing-function: var(--ease-out);
}
43.85%,
62% {
clip-path: inset(0 0 0 0);
opacity: 1;
animation-timing-function: var(--ease-out);
}
63.85%,
79.99% {
clip-path: inset(0 4ch 0 0);
opacity: 1;
}
80%,
100% {
clip-path: inset(0 15ch 0 0);
opacity: 0;
}
}
@keyframes anchor {
0%,
13.99% {
opacity: 0;
}
14%,
79.99% {
opacity: 1;
}
80%,
100% {
opacity: 0;
}
}
/* 500ms on, 500ms off; each keypress restarts the phase on "on" and
holds it through the glide and 500ms past the landing. */
@keyframes blink {
0%,
1.09% {
opacity: 0;
}
1.1%,
10.71% {
opacity: 1;
}
10.72%,
13.99% {
opacity: 0;
}
14%,
25.47% {
opacity: 1;
}
25.48%,
27.99% {
opacity: 0;
}
28%,
39.47% {
opacity: 1;
}
39.48%,
41.99% {
opacity: 0;
}
42%,
53.47% {
opacity: 1;
}
53.48%,
61.99% {
opacity: 0;
}
62%,
73.47% {
opacity: 1;
}
73.48%,
79.99% {
opacity: 0;
}
80%,
91.47% {
opacity: 1;
}
91.48%,
100% {
opacity: 0;
}
}
@keyframes reel {
0%,
13.99% {
transform: translateY(-5.2em);
}
14%,
61.99% {
transform: translateY(0);
}
62%,
79.99% {
transform: translateY(-2.6em);
}
80%,
100% {
transform: translateY(-5.2em);
}
}
@keyframes cue {
0%,
12% {
opacity: 0.45;
}
13.99% {
opacity: 0;
}
14% {
opacity: 0.2;
animation-timing-function: var(--ease-out);
}
17%,
26% {
opacity: 1;
}
27.99% {
opacity: 0;
}
28% {
opacity: 0.2;
animation-timing-function: var(--ease-out);
}
31%,
40% {
opacity: 1;
}
41.99% {
opacity: 0;
}
42% {
opacity: 0.2;
animation-timing-function: var(--ease-out);
}
45%,
60% {
opacity: 1;
}
61.99% {
opacity: 0;
}
62% {
opacity: 0.2;
animation-timing-function: var(--ease-out);
}
65%,
78% {
opacity: 1;
}
79.99% {
opacity: 0;
}
80% {
opacity: 0.2;
animation-timing-function: var(--ease-out);
}
83%,
94% {
opacity: 1;
}
100% {
opacity: 0.45;
}
}
@media (prefers-reduced-motion: reduce) {
/* The glide goes: caret and band step together to each word stop on
the keypress frame, so the selection still grows from its anchor a
word at a time — on a clock 1.6x slower. */
.sel,
.anchor,
.caret,
.reel {
animation-duration: calc(var(--t) * 1.6);
}
.caret {
animation-name: caret-rm, blink;
}
.sel {
animation-name: sel-rm;
}
@keyframes caret-rm {
0%,
13.99% {
transform: translateX(6ch);
}
14%,
27.99% {
transform: translateX(11ch);
}
28%,
41.99% {
transform: translateX(15ch);
}
42%,
61.99% {
transform: translateX(21ch);
}
62%,
79.99% {
transform: translateX(17ch);
}
80%,
100% {
transform: translateX(6ch);
}
}
@keyframes sel-rm {
0%,
13.99% {
clip-path: inset(0 15ch 0 0);
opacity: 0;
}
14%,
27.99% {
clip-path: inset(0 10ch 0 0);
opacity: 1;
}
28%,
41.99% {
clip-path: inset(0 6ch 0 0);
opacity: 1;
}
42%,
61.99% {
clip-path: inset(0 0 0 0);
opacity: 1;
}
62%,
79.99% {
clip-path: inset(0 4ch 0 0);
opacity: 1;
}
80%,
100% {
clip-path: inset(0 15ch 0 0);
opacity: 0;
}
}
}
</style>
</head>
<body>
<div class="card">
<p class="eyebrow">client.ts</p>
<div
class="code"
role="img"
aria-label="Starting before fetch, a selection grows one word at a time to cover fetch(url, opts, shrinks back by one word, then collapses as the caret returns to where the selection began."
><span class="sel"></span><div><span class="k">await</span> fetch(url, opts);</div><span class="anchor"></span><span class="caret"></span></div>
<div class="via" aria-hidden="true">
<span>via</span>
<span class="slot"
><span class="reel"
><span class="key"><b>⌥⇧→</b></span
><span class="key"><b>⌥⇧←</b></span
><span class="key"><b>←</b></span></span
></span
>
</div>
</div>
</body>
</html>
The variant family
Same idea, one axis moved. Compare them side by side before you commit.