CSS Animation Example: Circular Dash
The "Circular Dash" is an elegant loading spinner favored by Material Design frameworks, where a circular stroke stretches and contracts while rotating.
This animation is created by combining two separate @keyframes across two elements. First, the outer <svg> container revolves using a standard transform: rotate(). Second, the inner <circle> element's drawn line expands and contracts.
This expanding/contracting effect is achieved by animating two SVG-specific CSS properties: stroke-dasharray (which breaks the line into alternating dashes and gaps) and stroke-dashoffset (which dictates where the dash pattern starts drawing).
Here is the code to create the Circular Dash animation.
Accessibility Considerations
As with many loading indicators, complete removal of the CSS animation when the prefers-reduced-motion media query detects a user's preference for minimal motion is ill-advised since it could look broken.
Instead, we halt the rapid expanding/contracting of the stroke-dasharray line, leaving a static visible segment, and significantly slow down the speed of the outer container's rotation, resulting in a gentle, non-distracting loading state.
@media (prefers-reduced-motion: reduce) {
.circular-loader {
/* Still rotate, but extremely slowly */
animation-duration: 10s;
}
.circular-loader circle {
/* Disable the rapid dash stretching */
animation: none;
stroke-dasharray: 60, 200; /* Create a static segment */
}
}