CSS loader and loading GIF generator

Loading spinners made with CSS alone — a ring, dots, bars, a pulse or a ripple. Pick the colour, size and speed, then copy the CSS and HTML, or download the same loader as an animated GIF.

Loader
Colours

The background colour is only for the preview and the GIF — the CSS loader itself has no background.

Code
.loader {
  --d: 1000ms;
  width: 48px;
  height: 48px;
  box-sizing: border-box;
  border: 5px solid rgb(79 70 229 / 0.2);
  border-top-color: #4f46e5;
  border-radius: 50%;
  animation: loader-ring var(--d) linear infinite;
}
@keyframes loader-ring {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .loader { --d: 3000ms; }
}
Animated GIF

25 frames at 40 ms each.

How the loaders are made

Each loader is one div with the class loader. The ring and dual ring are that element alone: a circle with a thick border, one side (or two opposite sides) in the loader colour, turned by a @keyframes rotation. The others put a few empty spans inside it — 8 dots round a circle, 3 dots in a row, 5 bars, 1 or 2 circles, a 3 × 3 grid — that all run the same keyframes, each started part-way through the cycle with a negative animation-delay. That is what makes the dots light up in turn and the bars ripple from left to right, and it means the loader is already mid-motion on the first frame instead of starting from rest.

The GIF

For places where CSS can't run — an email, a chat message, an old CMS, a slide — the GIF button draws one full cycle of the same loader frame by frame in your browser and saves it as a looping animated GIF. Nothing is uploaded. A GIF can only show a frame for a whole number of hundredths of a second, so the frame count is chosen to make the loop as close to your cycle length as it can be (within 4%).

GIF colours are either fully solid or fully clear — there is no half-transparency. With Transparent background on, any pixel at least 13% covered is kept and blended with the background colour, so the smooth edges of the shapes are mixed for that colour: set the background colour to the colour of the page the GIF will sit on. With it off, the GIF has a solid background in that colour.

How we test it

81 loaders across all 8 styles are checked in Chrome 157. The CSS and HTML you copy are pasted into a page, every animation is stopped at six moments of the cycle and photographed, and each photo is compared with the GIF frame for the same moment — 486 frames, 7,337,454 pixels, with at most 1.04% of pixels on any frame differing (the smoothing along edges). The first and last moments of a cycle must look the same, so the loop has no jump; with reduced motion switched on every animation and delay must be exactly 3× longer. 64 GIFs (1,592 frames) are opened again by Chrome's own image decoder: frame count, each frame's time, size, which pixels are transparent and the colours must all match. Deliberately broken versions — delays with the wrong sign, a spin in the wrong direction, a keyframe moved, dots scaled from the corner, no reduced-motion rule, GIF frames in reverse, frame times in the wrong unit, transparency dropped, a GIF compressor that changes code size one step late — must each be caught.

Questions

How do I show and hide the loader?

Put the HTML where the content will appear and remove it (or add the hidden attribute) when the content has loaded. The CSS can stay on the page — it does nothing without the element.

Can I use two loaders with different colours?

Rename the class in one copy (for example loader → loader-2) in both the CSS and the HTML, and the keyframes name too if you change the style.

CSS or GIF — which should I use?

CSS on websites: it is a few hundred bytes, stays sharp at any zoom and slows down for people who ask for reduced motion. Use the GIF where CSS is not allowed, such as email.

Can I use the loaders in commercial work?

Yes. They are built in your browser from the style, colours and sizes you choose; there is nothing to credit.