AI CSS Animations

Circular Progress with Percentage

A ring that fills clockwise while the number in the middle counts up to 100%. The counter is pure CSS using a registered custom property, so there is no JavaScript to wire up.

Also known as: percentage loader, radial progress, progress ring.

HTML

<div class="ldr-circular-progress" role="progressbar" aria-label="Loading"></div>

CSS

@property --ldr-p {
  syntax: "<integer>";
  initial-value: 0;
  inherits: true;
}
.ldr-circular-progress {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  --t: calc(var(--s) / 9);
  position: relative;
  display: grid;
  place-items: center;
  width: var(--s);
  height: var(--s);
  font: 600 calc(var(--s) / 4.5) system-ui, sans-serif;
  color: var(--c);
  animation: ldr-circular-progress-count 3s ease-in-out infinite;
}
.ldr-circular-progress::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--ldr-p) * 1%), color-mix(in srgb, var(--ldr-color, #3b82f6) 15%, transparent) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--t)), #000 calc(100% - var(--t) + 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - var(--t)), #000 calc(100% - var(--t) + 1px));
}
.ldr-circular-progress::after {
  counter-reset: ldr-p var(--ldr-p);
  content: counter(ldr-p) "%";
}
@keyframes ldr-circular-progress-count {
  0%        { --ldr-p: 0; }
  85%, 100% { --ldr-p: 100; }
}

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