AI CSS Animations

Battery Charging Loader

A battery outline that fills from empty to full, then resets. Good for uploads, installs and anything with a clear 'done' at the end.

Also known as: charging animation, battery fill.

HTML

<div class="ldr-battery" role="status" aria-label="Loading"></div>

CSS

.ldr-battery {
  --s: var(--ldr-size, 48px);
  --c: var(--ldr-color, #3b82f6);
  position: relative;
  width: var(--s);
  height: calc(var(--s) / 2);
  padding: calc(var(--s) / 20);
  border: calc(var(--s) / 20) solid var(--c);
  border-radius: calc(var(--s) / 10);
}
.ldr-battery::before {
  content: "";
  position: absolute;
  top: 30%;
  right: calc(var(--s) / -7);
  width: calc(var(--s) / 12);
  height: 40%;
  border-radius: 0 calc(var(--s) / 30) calc(var(--s) / 30) 0;
  background: var(--c);
}
.ldr-battery::after {
  content: "";
  display: block;
  height: 100%;
  border-radius: calc(var(--s) / 24);
  background: var(--c);
  transform-origin: 0 50%;
  animation: ldr-battery-charge 2.4s ease-in-out infinite;
}
@keyframes ldr-battery-charge {
  0%        { transform: scaleX(0); }
  80%, 100% { transform: scaleX(1); }
}

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