A traffic light that runs the real sequence: top, then bottom, then middle, like red, green, amber. Three lamps share one keyframe and differ only by delay, so retinting is one variable.
Also known as: traffic signal animation, stoplight loader css, red yellow green loader.
<div class="ldr-traffic-light" role="status" aria-label="Loading"> <span style="--d: 0s"></span><span style="--d: 1.6s"></span><span style="--d: 0.8s"></span> </div>
.ldr-traffic-light {
--s: var(--ldr-size, 48px);
--c: var(--ldr-color, #3b82f6);
position: relative;
width: calc(var(--s) * 0.5);
height: var(--s);
}
.ldr-traffic-light::before {
content: "";
position: absolute;
inset: 0 0 12%;
box-sizing: border-box;
border: calc(var(--s) / 16) solid var(--c);
border-radius: calc(var(--s) * 0.14);
}
.ldr-traffic-light::after {
content: "";
position: absolute;
left: 50%;
bottom: 0;
width: calc(var(--s) / 10);
height: 12%;
margin-left: calc(var(--s) / -20);
background: var(--c);
}
.ldr-traffic-light span {
position: absolute;
left: 50%;
width: calc(var(--s) * 0.22);
height: calc(var(--s) * 0.22);
margin-left: calc(var(--s) * -0.11);
border-radius: 50%;
background: color-mix(in srgb, var(--ldr-color, #3b82f6) 20%, transparent);
}
.ldr-traffic-light span:nth-child(1) { top: 10%; }
.ldr-traffic-light span:nth-child(2) { top: 33%; }
.ldr-traffic-light span:nth-child(3) { top: 56%; }
.ldr-traffic-light span::after {
content: "";
position: absolute;
inset: 0;
border-radius: 50%;
background: var(--c);
box-shadow: 0 0 0 calc(var(--s) / 22) color-mix(in srgb, var(--ldr-color, #3b82f6) 25%, transparent);
opacity: 0;
animation: ldr-traffic-light-lamp 2.4s ease-in-out var(--d) infinite backwards;
}
@keyframes ldr-traffic-light-lamp {
0% { opacity: 0; transform: scale(0.8); }
4%, 30% { opacity: 1; transform: scale(1); }
36%, 100% { opacity: 0; transform: scale(0.8); }
}
@media (prefers-reduced-motion: reduce) {
.ldr-traffic-light, .ldr-traffic-light *, .ldr-traffic-light::before, .ldr-traffic-light::after, .ldr-traffic-light *::before, .ldr-traffic-light *::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.