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.
<div class="ldr-battery" role="status" aria-label="Loading"></div>
.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;
}
}--ldr-color on the element or a parent.
Currently previewing #3b82f6.--ldr-size. Every dimension in the snippet is
derived from it. Currently previewing 64px.animation shorthand.
Delays on the children are relative, so they keep their rhythm.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.