A square rotates while its corners round off into a circle and back. Two properties, one keyframe, and a lot of personality.
<div class="ldr-spinning-square" role="status" aria-label="Loading"></div>
.ldr-spinning-square {
--s: var(--ldr-size, 48px);
--c: var(--ldr-color, #3b82f6);
width: calc(var(--s) * 0.75);
height: calc(var(--s) * 0.75);
margin: calc(var(--s) * 0.125);
background: var(--c);
animation: ldr-spinning-square-morph 2s ease-in-out infinite;
}
@keyframes ldr-spinning-square-morph {
0% { transform: rotate(0deg); border-radius: 0; }
25% { transform: rotate(180deg); border-radius: 50%; }
50% { transform: rotate(180deg); border-radius: 50%; }
75% { transform: rotate(360deg); border-radius: 0; }
100% { transform: rotate(360deg); border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) {
.ldr-spinning-square, .ldr-spinning-square *, .ldr-spinning-square::before, .ldr-spinning-square::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.