Worm
React + Tailwind
const S = 0.3; // dot spacing, em
const H = 0.13; // worm thickness, em
const D = 0.08; // dot size, em
const MOVES = [
[0, 1],
[1, 2],
[2, 3],
[3, 0],
];
const STEP = 0.55;
const T = STEP * MOVES.length;
const MOTION = 0.74; // share of each step spent moving
const LAG = 0.38; // how long the tail waits behind the head, as a share of the move
const ease = (u: number) => (u < 0.5 ? 4 * u ** 3 : 1 - (-2 * u + 2) ** 3 / 2);
const clamp = (u: number) => Math.min(1, Math.max(0, u));
const pct = (t: number) => `${(t * 100).toFixed(2)}%`;
// The edge facing the way it goes moves first and the other follows, so the
// worm stretches onto the next dot and then gathers itself up there.
const frames: string[] = [];
MOVES.forEach(([a, b], k) => {
const fwd = b > a;
for (let j = 0; j <= 12; j++) {
const u = j / 12;
const head = ease(clamp(u / (1 - LAG)));
const tail = ease(clamp((u - LAG) / (1 - LAG)));
const from = a * S;
const to = b * S;
const left = from + (to - from) * (fwd ? tail : head);
const right = from + H + (to - from) * (fwd ? head : tail);
frames.push(`${pct((k + u * MOTION) / MOVES.length)} { left: ${left.toFixed(4)}em; width: ${(right - left).toFixed(4)}em; }`);
}
});
frames.push(`100% { left: 0em; width: ${H}em; }`);
const css = `
.loader-worm { --ink: light-dark(#373a40, #f1f2f3); --track: light-dark(#cbced3, #393c41); position: relative; display: inline-block; font-size: 120px; width: ${(3 * S + H).toFixed(2)}em; height: ${H}em; }
.loader-worm__dot { position: absolute; top: ${((H - D) / 2).toFixed(3)}em; width: ${D}em; height: ${D}em; border-radius: 50%; background: var(--track); }
.loader-worm__worm { position: absolute; top: 0; left: 0; width: ${H}em; height: ${H}em; border-radius: ${H / 2}em; background: var(--ink); animation: loader-worm-crawl ${T.toFixed(2)}s infinite; }
@keyframes loader-worm-crawl {
${frames.join('\n ')}
}
@media (prefers-reduced-motion: reduce) {
.loader-worm__worm { animation: none; }
}
`;
export function Preview() {
return (
<>
<style href="kit-loaders-worm" precedence="kit">
{css}
</style>
<div className="loader-worm" role="status" aria-label="Loading">
{[0, 1, 2, 3].map((i) => (
<span key={i} className="loader-worm__dot" style={{ left: `${(i * S + (H - D) / 2).toFixed(3)}em` }} aria-hidden="true" />
))}
<span className="loader-worm__worm" aria-hidden="true" />
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
HTML
<div class="loader-worm" role="status" aria-label="Loading">
<span class="loader-worm__dot" style="left:0.025em" aria-hidden="true"></span>
<span class="loader-worm__dot" style="left:0.325em" aria-hidden="true"></span>
<span class="loader-worm__dot" style="left:0.625em" aria-hidden="true"></span>
<span class="loader-worm__dot" style="left:0.925em" aria-hidden="true"></span>
<span class="loader-worm__worm" aria-hidden="true"></span>
</div>CSS
.loader-worm { --ink: light-dark(#373a40, #f1f2f3); --track: light-dark(#cbced3, #393c41); position: relative; display: inline-block; font-size: 120px; width: 1.03em; height: 0.13em; }
.loader-worm__dot { position: absolute; top: 0.025em; width: 0.08em; height: 0.08em; border-radius: 50%; background: var(--track); }
.loader-worm__worm { position: absolute; top: 0; left: 0; width: 0.13em; height: 0.13em; border-radius: 0.065em; background: var(--ink); animation: loader-worm-crawl 2.20s infinite; }
@keyframes loader-worm-crawl {
0.00% { left: 0.0000em; width: 0.1300em; }
1.54% { left: 0.0000em; width: 0.1329em; }
3.08% { left: 0.0000em; width: 0.1533em; }
4.63% { left: 0.0000em; width: 0.2087em; }
6.17% { left: 0.0000em; width: 0.3114em; }
7.71% { left: 0.0002em; width: 0.3874em; }
9.25% { left: 0.0087em; width: 0.4126em; }
10.79% { left: 0.0423em; width: 0.3874em; }
12.33% { left: 0.1186em; width: 0.3114em; }
13.87% { left: 0.2213em; width: 0.2087em; }
15.42% { left: 0.2767em; width: 0.1533em; }
16.96% { left: 0.2971em; width: 0.1329em; }
18.50% { left: 0.3000em; width: 0.1300em; }
25.00% { left: 0.3000em; width: 0.1300em; }
26.54% { left: 0.3000em; width: 0.1329em; }
28.08% { left: 0.3000em; width: 0.1533em; }
29.63% { left: 0.3000em; width: 0.2087em; }
31.17% { left: 0.3000em; width: 0.3114em; }
32.71% { left: 0.3002em; width: 0.3874em; }
34.25% { left: 0.3087em; width: 0.4126em; }
35.79% { left: 0.3423em; width: 0.3874em; }
37.33% { left: 0.4186em; width: 0.3114em; }
38.88% { left: 0.5213em; width: 0.2087em; }
40.42% { left: 0.5767em; width: 0.1533em; }
41.96% { left: 0.5971em; width: 0.1329em; }
43.50% { left: 0.6000em; width: 0.1300em; }
50.00% { left: 0.6000em; width: 0.1300em; }
51.54% { left: 0.6000em; width: 0.1329em; }
53.08% { left: 0.6000em; width: 0.1533em; }
54.63% { left: 0.6000em; width: 0.2087em; }
56.17% { left: 0.6000em; width: 0.3114em; }
57.71% { left: 0.6002em; width: 0.3874em; }
59.25% { left: 0.6087em; width: 0.4126em; }
60.79% { left: 0.6423em; width: 0.3874em; }
62.33% { left: 0.7186em; width: 0.3114em; }
63.87% { left: 0.8213em; width: 0.2087em; }
65.42% { left: 0.8767em; width: 0.1533em; }
66.96% { left: 0.8971em; width: 0.1329em; }
68.50% { left: 0.9000em; width: 0.1300em; }
75.00% { left: 0.9000em; width: 0.1300em; }
76.54% { left: 0.8913em; width: 0.1387em; }
78.08% { left: 0.8301em; width: 0.1999em; }
79.63% { left: 0.6640em; width: 0.3660em; }
81.17% { left: 0.3558em; width: 0.6742em; }
82.71% { left: 0.1270em; width: 0.9023em; }
84.25% { left: 0.0261em; width: 0.9778em; }
85.79% { left: 0.0007em; width: 0.9023em; }
87.33% { left: 0.0000em; width: 0.6742em; }
88.88% { left: 0.0000em; width: 0.3660em; }
90.42% { left: 0.0000em; width: 0.1999em; }
91.96% { left: 0.0000em; width: 0.1387em; }
93.50% { left: 0.0000em; width: 0.1300em; }
100% { left: 0em; width: 0.13em; }
}
@media (prefers-reduced-motion: reduce) {
.loader-worm__worm { animation: none; }
}Goal: Create a "Worm" loader.
Visual behavior: A pill crawls along a row of four dots like a page indicator, stretching onto the next dot before its tail follows, then reaches all the way back.
Technique:
- Pure CSS: every motion is a keyframe animation, so the plain HTML version needs no script.
- Everything is sized in em from one font-size on the root, so changing that one value scales the whole loader.
- The leading edge moves first and the trailing edge follows a beat later, so the pill stretches onto the next dot and then gathers itself up there.
- After the last dot it reaches back over all four in one long stretch, like a carousel wrapping round to the start.
- The keyframes are generated from the moves, so changing the dot count or spacing in the code keeps the motion right.
Accessibility: The root has role="status" and aria-label="Loading"; everything inside it is aria-hidden. Under prefers-reduced-motion the pill sits on the first dot.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Worm" loader.
Visual behavior: A pill crawls along a row of four dots like a page indicator, stretching onto the next dot before its tail follows, then reaches all the way back.
Technique:
- Pure CSS: every motion is a keyframe animation, so the plain HTML version needs no script.
- Everything is sized in em from one font-size on the root, so changing that one value scales the whole loader.
- The leading edge moves first and the trailing edge follows a beat later, so the pill stretches onto the next dot and then gathers itself up there.
- After the last dot it reaches back over all four in one long stretch, like a carousel wrapping round to the start.
- The keyframes are generated from the moves, so changing the dot count or spacing in the code keeps the motion right.
Accessibility: The root has role="status" and aria-label="Loading"; everything inside it is aria-hidden. Under prefers-reduced-motion the pill sits on the first dot.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
A pill crawls along a row of four dots like a page indicator, stretching onto the next dot before its tail follows, then reaches all the way back.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- continuous, loop, morph
- Techniques
- keyframes, border radius
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
The root has role="status" and aria-label="Loading"; everything inside it is aria-hidden. Under prefers-reduced-motion the pill sits on the first dot.