Three tiles shuffle around a two by two board, each sliding into the empty slot in turn like a sliding puzzle. One keyframe; negative delays put each tile at its own point in the loop.
Also known as: sliding squares loader, sliding tiles loader, 15 puzzle loader.
<div class="ldr-sliding-puzzle" role="status" aria-label="Loading"> <span></span><span></span><span></span> </div>
.ldr-sliding-puzzle {
--s: var(--ldr-size, 48px);
--c: var(--ldr-color, #3b82f6);
--p: calc(var(--s) * 0.48);
position: relative;
width: var(--s);
height: var(--s);
border-radius: calc(var(--s) / 8);
background: color-mix(in srgb, var(--ldr-color, #3b82f6) 12%, transparent);
}
.ldr-sliding-puzzle span {
position: absolute;
top: calc(var(--s) * 0.04);
left: calc(var(--s) * 0.04);
width: calc(var(--s) * 0.44);
height: calc(var(--s) * 0.44);
border-radius: calc(var(--s) / 12);
background: var(--c);
animation: ldr-sliding-puzzle-slide 3.6s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
.ldr-sliding-puzzle span:nth-child(2) {
background: color-mix(in srgb, var(--c) 62%, #fff);
animation-delay: -2.4s;
}
.ldr-sliding-puzzle span:nth-child(3) {
background: color-mix(in srgb, var(--c) 70%, #000);
animation-delay: -1.2s;
}
@keyframes ldr-sliding-puzzle-slide {
0% { transform: translate(0, 0); }
5%, 25% { transform: translate(0, var(--p)); }
30%, 50% { transform: translate(var(--p), var(--p)); }
55%, 75% { transform: translate(var(--p), 0); }
80%, 100% { transform: translate(0, 0); }
}
@media (prefers-reduced-motion: reduce) {
.ldr-sliding-puzzle, .ldr-sliding-puzzle *, .ldr-sliding-puzzle::before, .ldr-sliding-puzzle::after, .ldr-sliding-puzzle *::before, .ldr-sliding-puzzle *::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.