AI CSS Animations

Square Line Chase Loader

A line one side long chases itself around a faint square track, speeding up along each edge and easing into the corners. Four bars share one clip-path keyframe, each rotated a quarter turn.

Also known as: border chase loader, square outline loader, line snake loader.

HTML

<div class="ldr-square-line-chase" 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-square-line-chase {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  --t: calc(var(--s) / 10);
  position: relative;
  width: calc(var(--s) * 0.9);
  height: calc(var(--s) * 0.9);
}
.ldr-square-line-chase::before {
  content: "";
  position: absolute;
  inset: 0;
  border: var(--t) solid color-mix(in srgb, var(--ldr-color, #3b82f6) 15%, transparent);
  border-radius: calc(var(--t) / 2);
}
.ldr-square-line-chase span {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: var(--t);
  border-radius: calc(var(--t) / 2);
  background: var(--c);
  transform: rotate(calc(var(--i) * 90deg));
  transform-origin: 50% calc(var(--s) * 0.45);
  clip-path: inset(0 100% 0 0);
  animation: ldr-square-line-chase-draw 2.4s cubic-bezier(0.65, 0, 0.35, 1) infinite;
  animation-delay: calc(var(--i) * 0.6s - 2.4s);
}
@keyframes ldr-square-line-chase-draw {
  0%        { clip-path: inset(0 100% 0 0); }
  25%       { clip-path: inset(0 0 0 0); }
  50%, 100% { clip-path: inset(0 0 0 100%); }
}

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