Swap
React + Tailwind
const S = 0.3; // dot spacing, em
const R = S / 2; // each swap circles the pair's midpoint
const DOT = 0.16;
const STEPS = 6; // left pair, right pair, three times over: everyone is home again
const STEP = 0.46;
const T = STEPS * STEP;
const MOTION = 0.7;
const ease = (u: number) => (u < 0.5 ? 4 * u ** 3 : 1 - (-2 * u + 2) ** 3 / 2);
const pct = (t: number) => `${(t * 100).toFixed(2)}%`;
const slot = [0, 1, 2];
const frames: string[][] = [[], [], []];
const at = (i: number, t: number, x: number, y: number, s: number, o: number, z: number) =>
frames[i].push(`${pct(t)} { transform: translate(${x.toFixed(4)}em, ${y.toFixed(4)}em) scale(${s.toFixed(3)}); opacity: ${o.toFixed(2)}; z-index: ${z}; }`);
slot.forEach((p, i) => at(i, 0, p * S, 0, 1, 1, 1));
for (let k = 0; k < STEPS; k++) {
const p = k % 2;
const over = slot.indexOf(p); // moves right, passing in front
const under = slot.indexOf(p + 1); // moves left, passing behind
const m = (p + 0.5) * S;
const t0 = k / STEPS;
for (let j = 0; j <= 10; j++) {
const e = ease(j / 10);
const t = t0 + ((j / 10) * MOTION) / STEPS;
const lift = Math.sin(Math.PI * e);
at(over, t, m - R * Math.cos(Math.PI * e), -R * lift, 1 + 0.24 * lift, 1, 2);
at(under, t, m + R * Math.cos(Math.PI * e), R * lift, 1 - 0.24 * lift, 1 - 0.45 * lift, 0);
}
slot[over] = p + 1;
slot[under] = p;
}
slot.forEach((p, i) => at(i, 1, p * S, 0, 1, 1, 1));
const css = `
.loader-swap { --ink: light-dark(#373a40, #f1f2f3); position: relative; display: inline-block; font-size: 120px; width: ${(2 * S + DOT).toFixed(2)}em; height: ${(2 * R + DOT).toFixed(2)}em; }
.loader-swap__dot { position: absolute; left: 0; top: ${R}em; width: ${DOT}em; height: ${DOT}em; border-radius: 50%; background: var(--ink); animation: ${T.toFixed(2)}s linear infinite; }
${frames.map((f, i) => `.loader-swap__dot:nth-child(${i + 1}) { animation-name: loader-swap-dot-${i}; transform: translateX(${i * S}em); }\n @keyframes loader-swap-dot-${i} {\n ${f.join('\n ')}\n }`).join('\n ')}
@media (prefers-reduced-motion: reduce) {
.loader-swap__dot { animation: none !important; }
}
`;
export function Preview() {
return (
<>
<style href="kit-loaders-swap" precedence="kit">
{css}
</style>
<div className="loader-swap" role="status" aria-label="Loading">
{[0, 1, 2].map((i) => (
<span key={i} className="loader-swap__dot" aria-hidden="true" />
))}
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet. No JavaScript.
HTML
<div class="loader-swap" role="status" aria-label="Loading">
<span class="loader-swap__dot" aria-hidden="true"></span>
<span class="loader-swap__dot" aria-hidden="true"></span>
<span class="loader-swap__dot" aria-hidden="true"></span>
</div>CSS
.loader-swap { --ink: light-dark(#373a40, #f1f2f3); position: relative; display: inline-block; font-size: 120px; width: 0.76em; height: 0.46em; }
.loader-swap__dot { position: absolute; left: 0; top: 0.15em; width: 0.16em; height: 0.16em; border-radius: 50%; background: var(--ink); animation: 2.76s linear infinite; }
.loader-swap__dot:nth-child(1) { animation-name: loader-swap-dot-0; transform: translateX(0em); }
@keyframes loader-swap-dot-0 {
0.00% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 1; }
0.00% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
1.17% { transform: translate(0.0000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
2.33% { transform: translate(0.0008em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
3.50% { transform: translate(0.0086em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
4.67% { transform: translate(0.0460em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
5.83% { transform: translate(0.1500em, -0.1500em) scale(1.240); opacity: 1.00; z-index: 2; }
7.00% { transform: translate(0.2540em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
8.17% { transform: translate(0.2914em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
9.33% { transform: translate(0.2992em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
10.50% { transform: translate(0.3000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
11.67% { transform: translate(0.3000em, -0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
16.67% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
17.83% { transform: translate(0.3000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
19.00% { transform: translate(0.3008em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
20.17% { transform: translate(0.3086em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
21.33% { transform: translate(0.3460em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
22.50% { transform: translate(0.4500em, -0.1500em) scale(1.240); opacity: 1.00; z-index: 2; }
23.67% { transform: translate(0.5540em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
24.83% { transform: translate(0.5914em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
26.00% { transform: translate(0.5992em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
27.17% { transform: translate(0.6000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
28.33% { transform: translate(0.6000em, -0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
50.00% { transform: translate(0.6000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
51.17% { transform: translate(0.6000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
52.33% { transform: translate(0.5992em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
53.50% { transform: translate(0.5914em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
54.67% { transform: translate(0.5540em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
55.83% { transform: translate(0.4500em, 0.1500em) scale(0.760); opacity: 0.55; z-index: 0; }
57.00% { transform: translate(0.3460em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
58.17% { transform: translate(0.3086em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
59.33% { transform: translate(0.3008em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
60.50% { transform: translate(0.3000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
61.67% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
66.67% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
67.83% { transform: translate(0.3000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
69.00% { transform: translate(0.2992em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
70.17% { transform: translate(0.2914em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
71.33% { transform: translate(0.2540em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
72.50% { transform: translate(0.1500em, 0.1500em) scale(0.760); opacity: 0.55; z-index: 0; }
73.67% { transform: translate(0.0460em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
74.83% { transform: translate(0.0086em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
76.00% { transform: translate(0.0008em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
77.17% { transform: translate(0.0000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
78.33% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
100.00% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 1; }
}
.loader-swap__dot:nth-child(2) { animation-name: loader-swap-dot-1; transform: translateX(0.3em); }
@keyframes loader-swap-dot-1 {
0.00% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 1; }
0.00% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
1.17% { transform: translate(0.3000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
2.33% { transform: translate(0.2992em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
3.50% { transform: translate(0.2914em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
4.67% { transform: translate(0.2540em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
5.83% { transform: translate(0.1500em, 0.1500em) scale(0.760); opacity: 0.55; z-index: 0; }
7.00% { transform: translate(0.0460em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
8.17% { transform: translate(0.0086em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
9.33% { transform: translate(0.0008em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
10.50% { transform: translate(0.0000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
11.67% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
33.33% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
34.50% { transform: translate(0.0000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
35.67% { transform: translate(0.0008em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
36.83% { transform: translate(0.0086em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
38.00% { transform: translate(0.0460em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
39.17% { transform: translate(0.1500em, -0.1500em) scale(1.240); opacity: 1.00; z-index: 2; }
40.33% { transform: translate(0.2540em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
41.50% { transform: translate(0.2914em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
42.67% { transform: translate(0.2992em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
43.83% { transform: translate(0.3000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
45.00% { transform: translate(0.3000em, -0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
50.00% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
51.17% { transform: translate(0.3000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
52.33% { transform: translate(0.3008em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
53.50% { transform: translate(0.3086em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
54.67% { transform: translate(0.3460em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
55.83% { transform: translate(0.4500em, -0.1500em) scale(1.240); opacity: 1.00; z-index: 2; }
57.00% { transform: translate(0.5540em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
58.17% { transform: translate(0.5914em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
59.33% { transform: translate(0.5992em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
60.50% { transform: translate(0.6000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
61.67% { transform: translate(0.6000em, -0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
83.33% { transform: translate(0.6000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
84.50% { transform: translate(0.6000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
85.67% { transform: translate(0.5992em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
86.83% { transform: translate(0.5914em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
88.00% { transform: translate(0.5540em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
89.17% { transform: translate(0.4500em, 0.1500em) scale(0.760); opacity: 0.55; z-index: 0; }
90.33% { transform: translate(0.3460em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
91.50% { transform: translate(0.3086em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
92.67% { transform: translate(0.3008em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
93.83% { transform: translate(0.3000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
95.00% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
100.00% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 1; }
}
.loader-swap__dot:nth-child(3) { animation-name: loader-swap-dot-2; transform: translateX(0.6em); }
@keyframes loader-swap-dot-2 {
0.00% { transform: translate(0.6000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 1; }
16.67% { transform: translate(0.6000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
17.83% { transform: translate(0.6000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
19.00% { transform: translate(0.5992em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
20.17% { transform: translate(0.5914em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
21.33% { transform: translate(0.5540em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
22.50% { transform: translate(0.4500em, 0.1500em) scale(0.760); opacity: 0.55; z-index: 0; }
23.67% { transform: translate(0.3460em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
24.83% { transform: translate(0.3086em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
26.00% { transform: translate(0.3008em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
27.17% { transform: translate(0.3000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
28.33% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
33.33% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
34.50% { transform: translate(0.3000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
35.67% { transform: translate(0.2992em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
36.83% { transform: translate(0.2914em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
38.00% { transform: translate(0.2540em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
39.17% { transform: translate(0.1500em, 0.1500em) scale(0.760); opacity: 0.55; z-index: 0; }
40.33% { transform: translate(0.0460em, 0.1080em) scale(0.827); opacity: 0.68; z-index: 0; }
41.50% { transform: translate(0.0086em, 0.0499em) scale(0.920); opacity: 0.85; z-index: 0; }
42.67% { transform: translate(0.0008em, 0.0151em) scale(0.976); opacity: 0.95; z-index: 0; }
43.83% { transform: translate(0.0000em, 0.0019em) scale(0.997); opacity: 0.99; z-index: 0; }
45.00% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 0; }
66.67% { transform: translate(0.0000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
67.83% { transform: translate(0.0000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
69.00% { transform: translate(0.0008em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
70.17% { transform: translate(0.0086em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
71.33% { transform: translate(0.0460em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
72.50% { transform: translate(0.1500em, -0.1500em) scale(1.240); opacity: 1.00; z-index: 2; }
73.67% { transform: translate(0.2540em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
74.83% { transform: translate(0.2914em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
76.00% { transform: translate(0.2992em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
77.17% { transform: translate(0.3000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
78.33% { transform: translate(0.3000em, -0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
83.33% { transform: translate(0.3000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
84.50% { transform: translate(0.3000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
85.67% { transform: translate(0.3008em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
86.83% { transform: translate(0.3086em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
88.00% { transform: translate(0.3460em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
89.17% { transform: translate(0.4500em, -0.1500em) scale(1.240); opacity: 1.00; z-index: 2; }
90.33% { transform: translate(0.5540em, -0.1080em) scale(1.173); opacity: 1.00; z-index: 2; }
91.50% { transform: translate(0.5914em, -0.0499em) scale(1.080); opacity: 1.00; z-index: 2; }
92.67% { transform: translate(0.5992em, -0.0151em) scale(1.024); opacity: 1.00; z-index: 2; }
93.83% { transform: translate(0.6000em, -0.0019em) scale(1.003); opacity: 1.00; z-index: 2; }
95.00% { transform: translate(0.6000em, -0.0000em) scale(1.000); opacity: 1.00; z-index: 2; }
100.00% { transform: translate(0.6000em, 0.0000em) scale(1.000); opacity: 1.00; z-index: 1; }
}
@media (prefers-reduced-motion: reduce) {
.loader-swap__dot { animation: none !important; }
}Goal: Create a "Swap" loader.
Visual behavior: Three dots trade places in pairs, each pair circling round each other with one passing in front and one behind.
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 left pair swaps, then the right pair, three times over, after which every dot is home again and the loop closes.
- Each swap is a half circle round the pair midpoint. The dot going over grows a little and the one going under shrinks and dims, so they pass in front of and behind each other.
- The keyframes for all three dots are generated by playing the swaps through, so they always agree.
Accessibility: The root has role="status" and aria-label="Loading"; everything inside it is aria-hidden. Under prefers-reduced-motion the three dots rest in a row.
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 "Swap" loader.
Visual behavior: Three dots trade places in pairs, each pair circling round each other with one passing in front and one behind.
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 left pair swaps, then the right pair, three times over, after which every dot is home again and the loop closes.
- Each swap is a half circle round the pair midpoint. The dot going over grows a little and the one going under shrinks and dims, so they pass in front of and behind each other.
- The keyframes for all three dots are generated by playing the swaps through, so they always agree.
Accessibility: The root has role="status" and aria-label="Loading"; everything inside it is aria-hidden. Under prefers-reduced-motion the three dots rest in a row.
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
Three dots trade places in pairs, each pair circling round each other with one passing in front and one behind.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- continuous, loop, delay stagger
- Techniques
- keyframes, transform only
- 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 three dots rest in a row.