AI CSS Animations

Infinity Loader

A stroke chases itself around an infinity symbol on top of a faint track. The SVG path uses pathLength so the dash math is in round numbers.

Also known as: figure eight loader, infinite loop animation.

HTML

<svg class="ldr-infinity" viewBox="0 0 100 50" role="status" aria-label="Loading">
  <path class="ldr-infinity-track" pathLength="100" d="M50 25 C50 5 15 5 15 25 C15 45 50 45 50 25 C50 5 85 5 85 25 C85 45 50 45 50 25" fill="none" stroke-width="5" />
  <path class="ldr-infinity-run" pathLength="100" d="M50 25 C50 5 15 5 15 25 C15 45 50 45 50 25 C50 5 85 5 85 25 C85 45 50 45 50 25" fill="none" stroke-width="5" />
</svg>

CSS

.ldr-infinity {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  width: calc(var(--s) * 1.6);
  height: calc(var(--s) * 0.8);
}
.ldr-infinity-track {
  stroke: color-mix(in srgb, var(--ldr-color, #3b82f6) 18%, transparent);
}
.ldr-infinity-run {
  stroke: var(--c);
  stroke-linecap: round;
  stroke-dasharray: 28 72;
  animation: ldr-infinity-run 1.6s linear infinite;
}
@keyframes ldr-infinity-run {
  to { stroke-dashoffset: -100; }
}

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