AI CSS Animations

Filling Square Loader

A square outline flips over empty, fills from the bottom, flips again while full, then drains. The classic hourglass square, redone with scaleY and a swapped transform-origin instead of height.

Also known as: square fill loader, hourglass square loader, rotating fill square.

HTML

<div class="ldr-filling-square" role="status" aria-label="Loading"></div>

CSS

.ldr-filling-square {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  width: calc(var(--s) * 0.8);
  height: calc(var(--s) * 0.8);
  margin: calc(var(--s) * 0.1);
  padding: calc(var(--s) / 24);
  border: calc(var(--s) / 14) solid var(--c);
  border-radius: calc(var(--s) / 20);
  animation: ldr-filling-square-flip 2.4s cubic-bezier(0.7, 0, 0.3, 1) infinite;
}
.ldr-filling-square::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--s) / 60);
  background: var(--c);
  animation: ldr-filling-square-fill 2.4s cubic-bezier(0.45, 0, 0.55, 1) infinite;
}
@keyframes ldr-filling-square-flip {
  0%        { transform: rotate(0deg); }
  25%, 50%  { transform: rotate(180deg); }
  75%, 100% { transform: rotate(360deg); }
}
@keyframes ldr-filling-square-fill {
  0%, 25% { transform: scaleY(0); transform-origin: 50% 0; }
  50%     { transform: scaleY(1); transform-origin: 50% 0; }
  75%     { transform: scaleY(1); transform-origin: 50% 100%; }
  100%    { transform: scaleY(0); transform-origin: 50% 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .ldr-filling-square, .ldr-filling-square *, .ldr-filling-square::before, .ldr-filling-square::after, .ldr-filling-square *::before, .ldr-filling-square *::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