Loader set
Six CSS-only loaders behind one component: hopping dots, level bars, stretching ring, tumbling square, ripple pulse and a running line.
import type { CSSProperties } from "react";
import "./loader.css";
export type LoaderVariant =
"dots" | "bars" | "ring" | "square" | "pulse" | "line";
type LoaderProps = {
variant?: LoaderVariant;
/** Read out by screen readers. Say what is loading, not just "Loading". */
label?: string;
/** Size in pixels. The line loader is 2.6 times this wide and stays 4px tall. */
size?: number;
/** Any CSS color. Defaults to the text color. */
color?: string;
};
// How many moving parts each variant draws.
const PARTS: Record<LoaderVariant, number> = {
dots: 3,
bars: 5,
ring: 1,
square: 1,
pulse: 2,
line: 1,
};
/**
* Loader
* Six CSS-only loaders behind one component. No JavaScript runs while they
* animate, so they keep moving even when the main thread is busy.
*/
export function Loader({
variant = "dots",
label = "Loading",
size = 48,
color,
}: LoaderProps) {
const style = {
"--gu-loader-size": `${size}px`,
...(color ? { "--gu-loader-color": color } : {}),
} as CSSProperties;
return (
<span
className={`gu-loader gu-loader--${variant}`}
role="status"
style={style}
>
<span className="gu-loader__sr">{label}</span>
<span className="gu-loader__art" aria-hidden="true">
{Array.from({ length: PARTS[variant] }, (_, i) => (
<i key={i} style={{ "--i": i } as CSSProperties} />
))}
</span>
</span>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Loader set
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
Six loaders behind one component, all pure CSS: no JavaScript runs while they animate, so they keep moving even when the page is busy.
## Variants
- dots: three dots (20% of the size) hop in turn, 0.12s apart, squashing as they land (0.9s loop).
- bars: five rounded bars scale between 30% and 100% height from the bottom, offset by 0.18s (1.1s loop).
- ring: a ring (9% border) spins once a second while a clip-path polygon stretches and shrinks the visible arc (1.6s, alternate).
- square: a block (34% of the size) tumbles around the inside edge of a faint square, rotating 90° per side (1.8s, ease in-out).
- pulse: a solid centre dot with two rings that ripple out to 3.8× and fade, 0.9s apart.
- line: a thin 4px track with a 40% segment running across it (1.3s). It is 2.6× the size wide, for page tops and buttons.
## Look
Size via --gu-loader-size (the `size` prop, default 48px). Color via --gu-loader-color, or the current text color. Demo: six tiles in an auto-fill grid (min 180px), each with the loader and its name; the Ring tile is orange with ink.
## Accessibility
- Each loader is role="status" with a visually hidden label. Say what is loading ("Saving changes"), not only "Loading".
- prefers-reduced-motion: nothing travels or spins. Every loader breathes slowly (opacity 1 → 0.35 → 1 over 2s); the ring shows a fixed arc and the pulse shows its centre dot only.
## Props
variant ("dots" | "bars" | "ring" | "square" | "pulse" | "line"), label, size (px), color.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### Loader.tsx
```tsx
import type { CSSProperties } from "react";
import "./loader.css";
export type LoaderVariant =
"dots" | "bars" | "ring" | "square" | "pulse" | "line";
type LoaderProps = {
variant?: LoaderVariant;
/** Read out by screen readers. Say what is loading, not just "Loading". */
label?: string;
/** Size in pixels. The line loader is 2.6 times this wide and stays 4px tall. */
size?: number;
/** Any CSS color. Defaults to the text color. */
color?: string;
};
// How many moving parts each variant draws.
const PARTS: Record<LoaderVariant, number> = {
dots: 3,
bars: 5,
ring: 1,
square: 1,
pulse: 2,
line: 1,
};
/**
* Loader
* Six CSS-only loaders behind one component. No JavaScript runs while they
* animate, so they keep moving even when the main thread is busy.
*/
export function Loader({
variant = "dots",
label = "Loading",
size = 48,
color,
}: LoaderProps) {
const style = {
"--gu-loader-size": `${size}px`,
...(color ? { "--gu-loader-color": color } : {}),
} as CSSProperties;
return (
<span
className={`gu-loader gu-loader--${variant}`}
role="status"
style={style}
>
<span className="gu-loader__sr">{label}</span>
<span className="gu-loader__art" aria-hidden="true">
{Array.from({ length: PARTS[variant] }, (_, i) => (
<i key={i} style={{ "--i": i } as CSSProperties} />
))}
</span>
</span>
);
}
```
### loader.css
```css
.gu-loader {
--s: var(--gu-loader-size, 48px);
--c: var(--gu-loader-color, currentColor);
display: inline-grid;
place-items: center;
width: var(--s);
height: var(--s);
color: inherit;
}
.gu-loader__sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
}
.gu-loader__art {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
}
.gu-loader__art i {
display: block;
background: var(--c);
}
/* Dots: three dots hop in turn, squashing a little as they land. */
.gu-loader--dots .gu-loader__art {
gap: calc(var(--s) * 0.1);
}
.gu-loader--dots i {
width: calc(var(--s) * 0.2);
aspect-ratio: 1;
border-radius: 50%;
animation: gu-loader-hop 0.9s cubic-bezier(0.45, 0, 0.55, 1) infinite;
animation-delay: calc(var(--i) * 0.12s);
}
@keyframes gu-loader-hop {
0%,
60%,
100% {
transform: translateY(0) scale(1, 1);
}
25% {
transform: translateY(-70%) scale(0.9, 1.1);
}
50% {
transform: translateY(0) scale(1.15, 0.85);
}
}
/* Bars: five bars rise and fall like a level meter. */
.gu-loader--bars .gu-loader__art {
gap: calc(var(--s) * 0.07);
}
.gu-loader--bars i {
width: calc(var(--s) * 0.12);
height: 70%;
border-radius: 99px;
transform-origin: 50% 100%;
animation: gu-loader-level 1.1s ease-in-out infinite;
animation-delay: calc(var(--i) * -0.18s);
}
@keyframes gu-loader-level {
0%,
100% {
transform: scaleY(0.3);
}
50% {
transform: scaleY(1);
}
}
/* Ring: an arc that spins while it stretches and shrinks. */
.gu-loader--ring i {
width: 86%;
aspect-ratio: 1;
border-radius: 50%;
background: none;
border: calc(var(--s) * 0.09) solid var(--c);
animation:
gu-loader-spin 1s linear infinite,
gu-loader-arc 1.6s ease-in-out infinite alternate;
}
@keyframes gu-loader-spin {
to {
rotate: 1turn;
}
}
@keyframes gu-loader-arc {
0% {
clip-path: polygon(50% 50%, 50% 0, 70% 0, 70% 0, 70% 0, 70% 0);
}
100% {
clip-path: polygon(50% 50%, 50% 0, 100% 0, 100% 100%, 0 100%, 0 30%);
}
}
/* Square: a block that tumbles around the edge of a square. */
.gu-loader--square .gu-loader__art {
outline: 2px solid color-mix(in srgb, var(--c) 25%, transparent);
outline-offset: -2px;
border-radius: 4px;
}
.gu-loader--square i {
position: absolute;
left: 0;
top: 0;
width: 34%;
aspect-ratio: 1;
border-radius: 3px;
animation: gu-loader-edge 1.8s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes gu-loader-edge {
0% {
translate: 0 0;
rotate: 0deg;
}
25% {
translate: calc(var(--s) * 0.66) 0;
rotate: 90deg;
}
50% {
translate: calc(var(--s) * 0.66) calc(var(--s) * 0.66);
rotate: 180deg;
}
75% {
translate: 0 calc(var(--s) * 0.66);
rotate: 270deg;
}
100% {
translate: 0 0;
rotate: 360deg;
}
}
/* Pulse: two rings ripple out from a still centre. */
.gu-loader--pulse .gu-loader__art::before {
content: "";
width: 26%;
aspect-ratio: 1;
border-radius: 50%;
background: var(--c);
}
.gu-loader--pulse i {
position: absolute;
inset: 0;
margin: auto;
width: 26%;
aspect-ratio: 1;
border-radius: 50%;
background: none;
border: 2px solid var(--c);
animation: gu-loader-ripple 1.8s cubic-bezier(0.2, 0.6, 0.35, 1) infinite;
animation-delay: calc(var(--i) * 0.9s);
}
@keyframes gu-loader-ripple {
0% {
scale: 1;
opacity: 1;
}
100% {
scale: 3.8;
opacity: 0;
}
}
/* Line: a thin track with a segment that runs across, for page tops and buttons. */
.gu-loader--line {
width: calc(var(--s) * 2.6);
height: auto;
}
.gu-loader--line .gu-loader__art {
height: 4px;
overflow: hidden;
border-radius: 99px;
background: color-mix(in srgb, var(--c) 18%, transparent);
}
.gu-loader--line i {
position: absolute;
inset: 0 auto 0 0;
width: 40%;
border-radius: inherit;
animation: gu-loader-run 1.3s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes gu-loader-run {
0% {
translate: -100% 0;
}
100% {
translate: 250% 0;
}
}
/* Reduced motion: nothing travels. Every loader just breathes slowly. */
@media (prefers-reduced-motion: reduce) {
.gu-loader__art i,
.gu-loader--ring i {
animation: gu-loader-breathe 2s ease-in-out infinite !important;
animation-delay: calc(var(--i, 0) * 0.3s) !important;
translate: none;
}
.gu-loader--ring i {
clip-path: polygon(50% 50%, 50% 0, 100% 0, 100% 100%, 0 100%, 0 30%);
}
.gu-loader--line i {
width: 100%;
}
.gu-loader--pulse i {
display: none;
}
}
@keyframes gu-loader-breathe {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.35;
}
}
```
You might also want
Next piece: Magnetic buttonCurtain page loader
Animations, intermediate
Confetti send button
Animations, beginner
Orbit loader
Animations, beginner