AI CSS Animations

Falling Blocks Loader

Three block pieces fall into a small well, one snapping a quarter turn and one shifting a column on the way, lock into a square with a thud, then flash and clear like a finished line.

Also known as: tetris loader, stacking blocks loader, block puzzle loader.

HTML

<div class="ldr-falling-blocks" role="status" aria-label="Loading">
  <div class="ldr-falling-blocks-stack">
    <div class="ldr-falling-blocks-piece"><span style="--x: 0; --y: 2"></span><span style="--x: 1; --y: 2"></span><span style="--x: 2; --y: 2"></span></div>
    <div class="ldr-falling-blocks-piece"><span style="--x: 0; --y: 0"></span><span style="--x: 0; --y: 1"></span><span style="--x: 1; --y: 1"></span></div>
    <div class="ldr-falling-blocks-piece"><span style="--x: 1; --y: 0"></span><span style="--x: 2; --y: 0"></span><span style="--x: 2; --y: 1"></span></div>
  </div>
</div>

CSS

.ldr-falling-blocks {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  --p: calc(var(--s) * 0.32);
  position: relative;
  width: var(--s);
  height: var(--s);
  padding: calc(var(--s) * 0.02);
  border-radius: calc(var(--s) / 14);
  box-shadow: inset 0 calc(var(--s) / -22) 0 color-mix(in srgb, var(--ldr-color, #3b82f6) 22%, transparent);
  animation: ldr-falling-blocks-thud 3.2s infinite;
}
.ldr-falling-blocks-stack {
  position: relative;
  width: 100%;
  height: 100%;
  animation: ldr-falling-blocks-clear 3.2s linear infinite;
}
.ldr-falling-blocks-piece {
  --f: var(--c);
  position: absolute;
  inset: 0;
}
.ldr-falling-blocks-piece span {
  position: absolute;
  left: calc(var(--x) * var(--p));
  top: calc(var(--y) * var(--p));
  width: calc(var(--p) - var(--s) * 0.03);
  height: calc(var(--p) - var(--s) * 0.03);
  border-radius: calc(var(--s) / 28);
  background: var(--f);
}
.ldr-falling-blocks-piece:nth-child(1) {
  animation: ldr-falling-blocks-drop1 3.2s infinite;
}
.ldr-falling-blocks-piece:nth-child(2) {
  --f: color-mix(in srgb, var(--c) 60%, #fff);
  transform-origin: 33.3% 33.3%;
  animation: ldr-falling-blocks-drop2 3.2s infinite, ldr-falling-blocks-snap 3.2s step-end infinite;
}
.ldr-falling-blocks-piece:nth-child(3) {
  --f: color-mix(in srgb, var(--c) 68%, #000);
  animation: ldr-falling-blocks-drop3 3.2s infinite, ldr-falling-blocks-shift 3.2s step-end infinite;
}
@keyframes ldr-falling-blocks-drop1 {
  0%        { translate: 0 calc(var(--p) * -1.9); opacity: 0; }
  3%        { translate: 0 calc(var(--p) * -1.75); opacity: 1; animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45); }
  11%, 100% { translate: 0 0; opacity: 1; }
}
@keyframes ldr-falling-blocks-drop2 {
  0%, 19%   { translate: 0 calc(var(--p) * -1.9); opacity: 0; }
  22%       { translate: 0 calc(var(--p) * -1.75); opacity: 1; animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45); }
  30%, 100% { translate: 0 0; opacity: 1; }
}
@keyframes ldr-falling-blocks-drop3 {
  0%, 38%   { translate: 0 calc(var(--p) * -1.9); opacity: 0; }
  41%       { translate: 0 calc(var(--p) * -1.75); opacity: 1; animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45); }
  49%, 100% { translate: 0 0; opacity: 1; }
}
@keyframes ldr-falling-blocks-snap {
  0%        { rotate: -90deg; }
  26%, 100% { rotate: 0deg; }
}
@keyframes ldr-falling-blocks-shift {
  0%        { transform: translateX(calc(var(--p) * -1)); }
  45%, 100% { transform: translateX(0); }
}
@keyframes ldr-falling-blocks-thud {
  0%, 11%, 15%, 30%, 34%, 49%, 53%, 100% { transform: translateY(0); }
  12%, 31%, 50% { transform: translateY(calc(var(--s) * 0.04)); }
}
@keyframes ldr-falling-blocks-clear {
  0%, 68%   { opacity: 1; transform: translateY(0); }
  72%       { opacity: 0.25; }
  76%       { opacity: 1; }
  80%       { opacity: 0.25; }
  84%       { opacity: 1; transform: translateY(0); animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45); }
  94%, 100% { opacity: 0; transform: translateY(calc(var(--p) * 0.5)); }
}

@media (prefers-reduced-motion: reduce) {
  .ldr-falling-blocks, .ldr-falling-blocks *, .ldr-falling-blocks::before, .ldr-falling-blocks::after, .ldr-falling-blocks *::before, .ldr-falling-blocks *::after {
    animation-duration: 3s;
  }
}

Customizing this loader

  • Color: set --ldr-color on the element or a parent. Currently previewing #3b82f6.
  • Size: set --ldr-size. Every dimension in the snippet is derived from it. Currently previewing 64px.
  • Speed: change the duration on the animation shorthand. Delays on the children are relative, so they keep their rhythm.
  • Accessibility: the root carries role="status" and an aria-label so screen readers announce the wait. The reduced-motion rule at the end slows the animation for users who asked for less motion.

Similar loaders