AI CSS Animations

Folding Zigzag Loader

A straight line folds up into a tight zigzag from both ends toward the middle, like a carpenter's ruler, then springs flat again. Each joint is a nested bar that rotates relative to its parent.

Also known as: zigzag line animation, folding ruler loader, accordion line loader.

HTML

<div class="ldr-zigzag-fold" role="status" aria-label="Loading">
  <i><span><span><span></span></span></span></i>
  <i><span><span><span></span></span></span></i>
</div>

CSS

.ldr-zigzag-fold {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  --w: calc(var(--s) / 3);
  --t: calc(var(--s) / 10);
  position: relative;
  width: calc(var(--s) * 1.7);
  height: var(--s);
}
.ldr-zigzag-fold i {
  position: absolute;
  top: 50%;
  left: 50%;
  animation: ldr-zigzag-fold-lift 2.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
.ldr-zigzag-fold i + i { scale: -1 1; }
.ldr-zigzag-fold span {
  position: absolute;
  top: calc(var(--t) / -2);
  left: calc(var(--t) / -2);
  width: var(--w);
  height: var(--t);
  border-radius: var(--s);
  background: var(--c);
  transform-origin: calc(var(--t) / 2) 50%;
  animation: ldr-zigzag-fold-a 2.2s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
.ldr-zigzag-fold span span {
  top: 0;
  left: calc(100% - var(--t));
  background: color-mix(in srgb, var(--ldr-color, #3b82f6) 50%, transparent);
  animation-name: ldr-zigzag-fold-b;
}
.ldr-zigzag-fold span span span {
  background: var(--c);
  animation-name: ldr-zigzag-fold-c;
}
@keyframes ldr-zigzag-fold-a {
  0%, 12%, 100% { transform: rotate(0deg); }
  45%, 62%      { transform: rotate(70deg); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
}
@keyframes ldr-zigzag-fold-b {
  0%, 12%, 100% { transform: rotate(0deg); }
  45%, 62%      { transform: rotate(-140deg); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
}
@keyframes ldr-zigzag-fold-c {
  0%, 12%, 100% { transform: rotate(0deg); }
  45%, 62%      { transform: rotate(140deg); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
}
@keyframes ldr-zigzag-fold-lift {
  0%, 12%, 100% { transform: translateY(0); }
  45%, 62%      { transform: translateY(calc((var(--w) - var(--t)) * -0.47)); animation-timing-function: cubic-bezier(0.34, 1.4, 0.64, 1); }
}

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