AI CSS Animations

Triangle Path Loader

A triangle outline draws itself around from one corner, then erases from the start while the shape turns a third of a turn. SVG stroke-dashoffset with pathLength keeps the dash math simple.

Also known as: triangle loader, svg triangle loader, drawing triangle spinner.

HTML

<div class="ldr-triangle-path" role="status" aria-label="Loading">
  <svg viewBox="0 0 100 100" aria-hidden="true">
    <polygon class="ldr-triangle-path-track" points="50,13.6 92,86.4 8,86.4" pathLength="100"></polygon>
    <polygon class="ldr-triangle-path-line" points="50,13.6 92,86.4 8,86.4" pathLength="100"></polygon>
  </svg>
</div>

CSS

.ldr-triangle-path {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  width: var(--s);
  height: var(--s);
}
.ldr-triangle-path svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 62.1%;
  animation: ldr-triangle-path-turn 1.8s linear infinite;
}
.ldr-triangle-path polygon {
  fill: none;
  stroke-width: 9;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.ldr-triangle-path-track {
  stroke: color-mix(in srgb, var(--ldr-color, #3b82f6) 16%, transparent);
}
.ldr-triangle-path-line {
  stroke: var(--c);
  stroke-dasharray: 100 100;
  animation: ldr-triangle-path-draw 1.8s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
@keyframes ldr-triangle-path-turn {
  to { transform: rotate(120deg); }
}
@keyframes ldr-triangle-path-draw {
  0%       { stroke-dashoffset: 100; }
  45%, 55% { stroke-dashoffset: 0; }
  100%     { stroke-dashoffset: -100; }
}

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