SVG animation examples use CSS, SMIL, or JavaScript to change an SVG element’s position, opacity, stroke, or geometry over time.
The examples below provide complete markup for common effects, including rotation, pulsing, drawing, horizontal movement, and script-driven motion. Each technique has a different balance of control, file size, and destination compatibility.

Three Ways to Animate SVG
Choose the technique that matches the environment where the graphic will appear. CSS is a practical choice for web interfaces and pages that already use a stylesheet. SMIL keeps the animation instruction inside the SVG document. JavaScript offers detailed control for interactive or coordinated motion, but it depends on the destination allowing scripts to run.
| Technique | How motion is expressed | Good fit | Main constraint |
|---|---|---|---|
| CSS keyframes | Animates properties such as transform, opacity, and stroke-dashoffset | Loops, hover effects, and interface feedback | The destination must preserve the required CSS |
| SMIL | Uses animation elements inside the SVG | Self-contained declarative motion | Support and preservation vary by destination |
| JavaScript | Updates SVG attributes or styles over time | Interactive and coordinated movement | Scripts may be blocked, removed, or sanitized |
For decorative motion, provide a reduced-motion alternative. A CSS media query can disable nonessential movement for readers who request less motion. SMIL and JavaScript examples can include a static fallback or use a separate reduced-motion version.
Rotate a Group with CSS
This example rotates a group around the center of its visible bounds. The small marker makes the rotation obvious; rotating a perfectly symmetrical circle by itself can look unchanged.
Complete SVG markup:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120" aria-label="Rotating marker"> <style> .rotating-group { transform-box: fill-box; transform-origin: center; animation: rotate-marker 2.4s linear infinite; } @keyframes rotate-marker { to { transform: rotate(360deg); } } </style> <g class="rotating-group"> <circle cx="60" cy="60" r="30" fill="#E0F2FE" /> <circle cx="60" cy="30" r="7" fill="#0369A1" /> </g> </svg>
The class connects the SVG group to the keyframes. The transform-box and transform-origin declarations establish a predictable center, while the linear timing function keeps the movement at a constant rate. Change the duration to control the speed and use a different timing function when the motion should accelerate, decelerate, or pause between cycles.
Pulse and Draw with CSS
Opacity animation is useful for a soft visual pulse. It changes the element’s transparency without moving its geometry or changing the final dimensions of the SVG canvas.
Opacity pulse:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120" aria-label="Pulsing circle"> <style> .pulse { animation: pulse-opacity 1.6s ease-in-out infinite alternate; } @keyframes pulse-opacity { from { opacity: 0.25; } to { opacity: 1; } } </style> <circle class="pulse" cx="60" cy="60" r="34" fill="#7C3AED" /> </svg>
A stroke-dash animation can suggest drawing, progress, or active processing. The pathLength value normalizes the circle’s path measurements to a simple scale, while the keyframes move the visible dash around the outline.
Animated stroke ring:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120" aria-label="Animated stroke ring"> <style> .dash-ring { fill: none; stroke: #F97316; stroke-width: 8; stroke-linecap: round; stroke-dasharray: 100; animation: dash-cycle 1.4s linear infinite; } @keyframes dash-cycle { to { stroke-dashoffset: 100; } } </style> <circle class="dash-ring" cx="60" cy="60" r="38" pathLength="100" /> </svg>
For pages that use several examples together, a shared reduced-motion rule can disable all three CSS effects:
@media (prefers-reduced-motion: reduce) { .rotating-group, .pulse, .dash-ring { animation: none; } }
Move a Shape with SMIL
SMIL defines animation directly inside the SVG. This example moves a circle horizontally by animating its cx attribute from 30 to 90 and then back again.
Complete SMIL example:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="120" height="120" aria-label="Horizontally moving circle"> <circle cx="30" cy="60" r="14" fill="#0F766E"> <animate attributeName="cx" values="30;90;30" dur="3s" repeatCount="indefinite" /> </circle> </svg>
The animation element remains inside the shape it controls, so no external stylesheet or script is required. The values establish the start, intermediate, and return positions; dur sets the duration; and repeatCount controls repetition. Because some editors, email clients, and publishing systems handle SVG animation elements differently, test the exact exported file rather than assuming that valid markup will be preserved.
Drive Motion with JavaScript
JavaScript is useful when the motion needs to respond to events or coordinate several elements. This example moves a dot back and forth with requestAnimationFrame, the browser API intended for visual updates.
Complete JavaScript example:
<svg xmlns="http://www.w3.org/2000/svg" id="moving-dot-demo" viewBox="0 0 120 120" width="120" height="120" aria-label="Moving dot"> <circle id="moving-dot" cx="18" cy="60" r="10" fill="#2563EB" /> <script> const dot = document.getElementById('moving-dot'); let direction = 1; function animateDot() { let x = Number(dot.getAttribute('cx')); if (x >= 102) direction = -1; if (x <= 18) direction = 1; dot.setAttribute('cx', String(x + direction * 0.5)); requestAnimationFrame(animateDot); } requestAnimationFrame(animateDot); </script> </svg>
The script reads the current cx value, changes its direction at the boundaries, and requests the next update. Give each embedded SVG unique element IDs if a page contains more than one scripted example. Also confirm that the destination permits inline scripts: a content system may remove the script element even when it preserves the surrounding SVG.
Build an Animated SVG Step by Step
- Set the destination and motion goal. Decide whether the graphic will run in a browser page, editor, email client, or content system. Choose CSS, SMIL, or JavaScript based on what that destination preserves.
- Prepare a complete base graphic. Start with an explicit width, height, matching viewBox, and accessible label. Draw the object in its resting position before adding motion so its geometry can be evaluated independently.
- Add one animated property. Use a CSS transform, opacity rule, or stroke-dashoffset for common effects. For SMIL, add an appropriate animation element inside the target shape. For JavaScript, update an attribute or style from a controlled loop.
- Define timing and repetition. Set the duration, delay, easing, and repeat behavior. CSS uses animation properties and keyframes; SMIL uses attributes such as dur and repeatCount; JavaScript controls timing through its scheduling code.
- Provide a reduced-motion option. Disable nonessential CSS animation with a prefers-reduced-motion query. For script-driven motion, stop or limit the update loop when reduced motion is requested. A static SVG can serve as the simplest fallback.
- Test the exact output in its final environment. Check that the graphic appears, moves as intended, repeats correctly, and keeps its expected size. Confirm that the host has not removed CSS, SMIL, scripts, or the SVG root.
- Save the source used for production. Keep the final markup and any generator settings needed to recreate the base graphic. For a seeded blob, save the seed together with its geometry, size, and color settings.
Use a Reproducible Blob as the Base Shape
The SVG Blob Generator can create a reproducible organic base shape for an animation, but it does not create the animation itself. Its export is deliberately static and contains no CSS classes, gradients, strokes, shadows, clipping paths, metadata, optimization passes, or raster fallbacks.
- Set the shape controls. Choose the vertex count, irregularity, square canvas size, and fill color.
- Randomize until the preview fits. Randomize Shape changes the seed while keeping the selected geometry and color settings in place. Record the displayed seed when the same result must be recreated later.
- Copy or download the markup. Test the resulting SVG in the destination application before adding or relying on animation behavior.
| Control | Supported value | Effect |
|---|---|---|
| Vertices | 3 through 12 | Sets the number of evenly spaced angular points |
| Irregularity | 0 through 100 percent | Controls deterministic radius variation; zero gives every vertex the same radius |
| Canvas | Three practical square presets within the stated 256–1024 pixel range | Sets the requested dimensions and matching viewBox |
| Fill | Strict six-digit HEX | Applies one solid fill color |
| Seed | Unsigned 32-bit value | Determines the radius pattern for the selected settings |
The same vertices, irregularity, size, color, and seed produce the same points, path data, and SVG markup. The generated document contains one path, an explicit width and height, a matching viewBox, and an accessible image label. Coordinates are rounded to two decimal places during serialization, and no shape or color is uploaded.
After copying the markup, add a class to the path or wrap the relevant shape in a group, then apply one of the CSS techniques shown above. You can also insert a SMIL animation element or a script into the SVG yourself. If you need to edit the path commands directly, the W3C SVG 2 path specification and MDN SVG path reference document the relevant path syntax.
Test the Final Animation
Valid SVG markup is only one part of delivery. Some publishing systems remove inline SVG or data URLs even when the underlying markup follows the SVG specification. Test the final file in every browser, editor, email client, or content system that will handle it.
- Check visible motion. Confirm that the element moves, the animation starts, and repeated cycles return to the expected state.
- Inspect the shape at different sizes. High irregularity can create tight bends or an unbalanced visual mass, so review the result at both large and small dimensions.
- Protect nearby text. If the graphic sits behind text, check the real color contrast and leave enough padding. The generator’s canvas margin does not guarantee readability.
- Verify fallback behavior. Check the reduced-motion version, the static fallback, and any controls that should pause the animation.
- Diagnose missing animation by layer. If nothing moves, determine whether the SVG was removed, the CSS was not preserved, SMIL is unsupported in the destination, the script was blocked, or a scripted element ID no longer matches.
If clipboard permission is denied, the blob generator keeps the complete markup visible in a read-only text area for manual selection. Its download is genuine SVG text encoded as a data URL, so compatible applications can continue treating it as vector geometry. The download does not create a persistent server file, and the filename includes the seed to help with organization.
Choose the Pattern That Fits
- Small interface feedback: Use a short opacity pulse, slight rotation, or transform that responds clearly without distracting from the task.
- Loading or active state: Use a moving stroke dash or a rotating group, then verify that the effect still communicates progress when color is unavailable.
- Ambient background shape: Use slow opacity or transform motion, preserve generous padding, and avoid placing important text over the busiest part of the silhouette.
- Guided demonstration: Use SMIL for simple declarative sequencing or JavaScript when several elements need coordinated updates.
- Reproducible blob artwork: Generate the static shape from a recorded seed, add motion manually, and save both the generator record and animated markup.
Start with one effect and confirm that it works in the destination. Once the baseline is stable, adjust the timing, color, motion path, or reduced-motion behavior without changing the underlying SVG structure unnecessarily.
If you're weighing options, Generate SVG Code for Patterns Without Path Markup covers this in detail.