kipluo
React6 min read2 steps

How to Build a Custom Loading Animation with CSS

Generic spinners tell users nothing about progress or personality. Learn how to animate SVG paths and transforms on the compositor thread while exposing proper progressbar semantics.

You needCSS KeyframesBasic SVG stroke-dasharray / stroke-dashoffset
Loading demo
Example animated loader with determinate progress, complete, and error states.Component page

1. Animate only transform and opacity for 60fps loaders

Animating width, height, top, or box-shadow inside a looping loader forces layout or paint on every frame—burning mobile CPU while your app is busy fetching or parsing data.

Stick strictly to transform (translate, scale, rotate), opacity, and SVG stroke-dashoffset on small viewBoxes.

OrbitLoader.css
.orbit-ring {
  transform-origin: 50% 50%;
  animation: orbit-spin 1.8s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}

@keyframes orbit-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .orbit-ring {
    animation: none;
  }
}

2. Support both indeterminate and determinate states

The cleanest loader API accepts an optional value (0–100). When value is undefined, run a gentle looping animation; when value is provided, drive stroke-dashoffset or scaleX directly from value and set aria-valuenow.

RingLoader.tsx
export function RingLoader({ value, label = "Loading" }: { value?: number; label?: string }) {
  const r = 36;
  const c = 2 * Math.PI * r;
  const clamped = value === undefined ? undefined : Math.max(0, Math.min(100, value));
  const offset = clamped === undefined ? c * 0.72 : c * (1 - clamped / 100);

  return (
    <div
      role="progressbar"
      aria-label={label}
      aria-valuemin={0}
      aria-valuemax={100}
      aria-valuenow={clamped}
      className="inline-grid place-items-center"
    >
      <svg width="88" height="88" viewBox="0 0 88 88" className={clamped === undefined ? "animate-spin" : ""}>
        <circle cx="44" cy="44" r={r} fill="none" stroke="currentColor" strokeOpacity="0.15" strokeWidth="6" />
        <circle
          cx="44"
          cy="44"
          r={r}
          fill="none"
          stroke="currentColor"
          strokeWidth="6"
          strokeLinecap="round"
          strokeDasharray={c}
          strokeDashoffset={offset}
          transform="rotate(-90 44 44)"
        />
      </svg>
    </div>
  );
}

Accessibility checklist

Tick each one off as you check your build. Your ticks stay in this browser.

0 of 3 checked

Build it yourself or install it

Build it yourself when

A single circular SVG ring or skeleton shimmer is all your app needs.

Install Kipluo when

You want 15 illustrated, textured loaders (Cat Walk, Planet Orbit, Coffee Brew, Hourglass, Fish Bowl, etc.) with complete/error states across React and Flutter.

Keep building