AI CSS Animations

Circle Bounce Loader

A ball ricochets around the inside of a ring at a constant angle, so its path closes into a faint five-pointed star, and the wall flashes where it hits. The trail is delayed copies.

Also known as: ball bouncing inside circle, circle billiard animation, bouncing ball in a ring.

HTML

<div class="ldr-circle-bounce" role="status" aria-label="Loading">
  <svg class="ldr-circle-bounce-star" viewBox="-50 -50 100 100" aria-hidden="true">
    <polygon points="0,-38.5 22.6,31.1 -36.6,-11.9 36.6,-11.9 -22.6,31.1" />
  </svg>
  <span class="ldr-circle-bounce-flash"></span>
  <span class="ldr-circle-bounce-ball" style="--k: 0"></span>
  <span class="ldr-circle-bounce-ball" style="--k: 1"></span>
  <span class="ldr-circle-bounce-ball" style="--k: 2"></span>
  <span class="ldr-circle-bounce-ball" style="--k: 3"></span>
  <span class="ldr-circle-bounce-ball" style="--k: 4"></span>
</div>

CSS

.ldr-circle-bounce {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  position: relative;
  width: var(--s);
  height: var(--s);
  box-sizing: border-box;
  border: calc(var(--s) / 24) solid color-mix(in srgb, var(--ldr-color, #3b82f6) 35%, transparent);
  border-radius: 50%;
}
.ldr-circle-bounce-star {
  position: absolute;
  top: calc(var(--s) / -24);
  left: calc(var(--s) / -24);
  width: var(--s);
  height: var(--s);
  overflow: visible;
}
.ldr-circle-bounce-star polygon {
  fill: none;
  stroke: color-mix(in srgb, var(--ldr-color, #3b82f6) 22%, transparent);
  stroke-width: 1px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
/* Steps round the rim by 144deg per bounce, and flares on each one. */
.ldr-circle-bounce-flash {
  position: absolute;
  inset: 0;
  animation: ldr-circle-bounce-step 2s steps(5) infinite;
}
.ldr-circle-bounce-flash::before {
  content: "";
  position: absolute;
  top: calc(var(--s) / -10);
  left: calc(50% - var(--s) / 10);
  width: calc(var(--s) / 5);
  height: calc(var(--s) / 5);
  box-sizing: border-box;
  border: calc(var(--s) / 30) solid var(--c);
  border-radius: 50%;
  animation: ldr-circle-bounce-flare 0.4s ease-out infinite;
}
.ldr-circle-bounce-ball {
  --d: calc(var(--s) * (0.15 - var(--k) * 0.02));
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--d);
  height: var(--d);
  margin: calc(var(--d) / -2);
  border-radius: 50%;
  background: var(--c);
  opacity: calc(1 - var(--k) * 0.2);
  animation: ldr-circle-bounce-path 2s linear infinite;
  animation-delay: calc(var(--k) * 0.04s - 2s);
}
@keyframes ldr-circle-bounce-path {
  0% { transform: translate(calc(var(--s) * 0.000), calc(var(--s) * -0.385)); }
  20% { transform: translate(calc(var(--s) * 0.226), calc(var(--s) * 0.311)); }
  40% { transform: translate(calc(var(--s) * -0.366), calc(var(--s) * -0.119)); }
  60% { transform: translate(calc(var(--s) * 0.366), calc(var(--s) * -0.119)); }
  80% { transform: translate(calc(var(--s) * -0.226), calc(var(--s) * 0.311)); }
  100% { transform: translate(calc(var(--s) * -0.000), calc(var(--s) * -0.385)); }
}
@keyframes ldr-circle-bounce-step {
  from { transform: rotate(0deg); }
  to   { transform: rotate(720deg); }
}
@keyframes ldr-circle-bounce-flare {
  from { transform: scale(0.3); opacity: 0.9; }
  to   { transform: scale(1.3); opacity: 0; }
}

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