AI CSS Animations

Folding Cube Loader

Four tiles of a diamond fold into place one after another, hold, then fold away in the same order. The SpinKit classic, built from rotateX and rotateY with per-tile perspective.

Also known as: spinkit folding cube, folding squares loader, fold cube spinner.

HTML

<div class="ldr-folding-cube" role="status" aria-label="Loading">
  <span style="--i: 0"></span><span style="--i: 1"></span><span style="--i: 2"></span><span style="--i: 3"></span>
</div>

CSS

.ldr-folding-cube {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  position: relative;
  width: calc(var(--s) * 0.68);
  height: calc(var(--s) * 0.68);
  margin: calc(var(--s) * 0.16);
  transform: rotate(45deg);
}
.ldr-folding-cube span {
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 50%;
  transform-origin: 100% 100%;
  transform: rotate(calc(var(--i) * 90deg));
}
.ldr-folding-cube span::before {
  content: "";
  position: absolute;
  inset: calc(var(--s) / 60);
  border-radius: calc(var(--s) / 30);
  background: var(--c);
  transform-origin: 100% 100%;
  animation: ldr-folding-cube-fold 2.4s cubic-bezier(0.45, 0, 0.55, 1) infinite both;
  animation-delay: calc(var(--i) * 0.3s);
}
.ldr-folding-cube span:nth-child(even)::before {
  background: color-mix(in srgb, var(--c) 72%, #000);
}
@keyframes ldr-folding-cube-fold {
  0%, 10% { transform: perspective(calc(var(--s) * 3)) rotateX(-180deg) rotateY(0deg); opacity: 0; }
  25%, 75% { transform: perspective(calc(var(--s) * 3)) rotateX(0deg) rotateY(0deg); opacity: 1; }
  90%, 100% { transform: perspective(calc(var(--s) * 3)) rotateX(0deg) rotateY(180deg); opacity: 0; }
}

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