AI CSS Animations

Newton's Cradle

Five hanging balls where the outer ones swing out and knock back in, one side then the other. A desk-toy loader for pages that want a little wit.

Also known as: pendulum balls loader, swinging balls.

HTML

<div class="ldr-newton-cradle" role="status" aria-label="Loading">
  <span></span><span></span><span></span><span></span><span></span>
</div>

CSS

.ldr-newton-cradle {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  position: relative;
  width: var(--s);
  height: var(--s);
}
.ldr-newton-cradle span {
  position: absolute;
  top: 0;
  width: 20%;
  height: 100%;
  transform-origin: 50% 0;
}
.ldr-newton-cradle span:nth-child(1) { left: 0; }
.ldr-newton-cradle span:nth-child(2) { left: 20%; }
.ldr-newton-cradle span:nth-child(3) { left: 40%; }
.ldr-newton-cradle span:nth-child(4) { left: 60%; }
.ldr-newton-cradle span:nth-child(5) { left: 80%; }
.ldr-newton-cradle span::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 80%;
  background: color-mix(in srgb, var(--ldr-color, #3b82f6) 45%, transparent);
}
.ldr-newton-cradle span::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--c);
}
.ldr-newton-cradle span:first-child { animation: ldr-newton-cradle-left 1.2s ease-in-out infinite; }
.ldr-newton-cradle span:last-child  { animation: ldr-newton-cradle-right 1.2s ease-in-out infinite; }
@keyframes ldr-newton-cradle-left {
  0%, 50%, 100% { transform: rotate(0deg); }
  25%           { transform: rotate(50deg); }
}
@keyframes ldr-newton-cradle-right {
  0%, 50%, 100% { transform: rotate(0deg); }
  75%           { transform: rotate(-50deg); }
}

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