Skip to main content

CSS Shape Loaders · #142 of 201

Swapping Squares — CSS Loader

Two squares moving around a 2×2 grid.

  • playful
  • no JavaScript
  • 1 div
Colour
#08754f

Edit the CSS above — the preview updates as you type. Colour, size and speed are applied to the code you copy.

How to use the Swapping Squares loader

  1. Copy the CSS above into your stylesheet (or a shape-quad-swap.css file).
  2. Add the markup where the loader should appear: <div class="loader" role="status" aria-label="Loading"></div>
  3. Change the colour with --loader-color, for example style="--loader-color:#2563eb".
  4. Hide or remove the element when your content has loaded.

How this CSS loader works

Swapping Squares is 15 lines of CSS on a single element. It is built with a CSS @keyframes animation and linear-gradient backgrounds. The animation runs on a 1.6s loop — use the speed control to make it faster or slower.

Because colours come from currentColor, one --loader-color variable re-colours every part of the loader, including faded tracks made with color-mix().