Animated SVG Spinners
One of the most common real-world uses for SVG animation is creating loading spinners and progress indicators. Because SVGs are lightweight and resolution-independent, they look great on any screen.
Method 1: The "Pulsing Dots" Spinner
This is easily achieved with the <animate> tag by targeting the opacity or r (radius) of several circles and offsetting their begin times:
Method 2: The Rotating Ring
This classic "spinner" effect uses two circles. The stroke of the foreground circle is broken into segments using stroke-dasharray and then rotated continuously using CSS:
Method 3: The Drawing Effect
By animating the stroke-dashoffset property, you can make a path appear as if it's being drawn or written in real-time. This is often used for "Success" checkmarks or logo animations:
To use this effect:
- Set
stroke-dasharrayto the total length of the path. - Set
stroke-dashoffsetto that same length (this hides the path). - Animate the
stroke-dashoffsetdown to 0 to "draw" the path.