Vectroy

SVG Animation and Motion Design: CSS Keyframes and Web Trends

Animated SVGs are standard in web design now. CSS keyframes bring SVGs to life without video. This covers when animation adds value vs when it is distraction.

December 20, 2026 · 8 min read

SVG animation on the modern web runs on CSS keyframes because they need no JavaScript, add no extra requests, and — for the two cheapest properties, transform and opacity — execute on the browser's compositor thread instead of the main thread. A self-drawing logomark, an icon that pulses on hover, a spinner that never ships a 400 KB GIF: each is a handful of keyframe rules attached to paths and groups inside an inline SVG, typically 0.2-1 KB of CSS animating a 2-30 KB vector file. The technique is easy; the craft is knowing which properties stay cheap, when SMIL or a JS library is genuinely better, and when the right animation is none.

How Do CSS Keyframes Animate SVG Elements?

CSS can animate any SVG element's presentation properties — fill, stroke, stroke-dashoffset, transform, opacity, filter — with the same @keyframes syntax used for HTML. The placement rule decides everything: CSS from your stylesheet reaches SVG elements only when the SVG is inline in the HTML document. An SVG loaded via <img> or CSS background-image cannot see page stylesheets, but it can still animate using a <style> block inside the SVG file itself — a self-contained animation that plays everywhere the file is referenced.

The minimal pulse pattern, class on a <g> or <path>:

  • .icon-pulse { animation: pulse 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
  • @keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

The two lines that make it work correctly are transform-box: fill-box and transform-origin: center. Without them, SVG transforms originate at the canvas origin (0,0) — the top-left of the viewBox — not the element's own center, so icons scale away from their corner and rotations swing like a pendulum. This is the single most common SVG animation bug, and transform-box: fill-box is supported in every current browser.

The Line-Draw Effect with stroke-dasharray

The self-drawing line trick sets a stroke's dash pattern and offset equal to the path length, then animates the offset to zero so the dash gap slides off the path:

  • .draw-on { stroke-dasharray: 1200; stroke-dashoffset: 1200; animation: draw 2.4s ease forwards; fill: none; }
  • @keyframes draw { to { stroke-dashoffset: 0; } }

Two constraints: it only works on stroked paths (fills cannot "draw"), and the dasharray value must be at least the path's total length — measure it exactly with path.getTotalLength() in JavaScript once, hard-code the number, or overshoot generously as above. A value too short makes the line blink instead of draw. For sequenced multi-path logos, stagger with animation-delay: 0.3s per path.

SMIL vs CSS Keyframes vs JavaScript Libraries: Which Should You Use?

Three families cover the field. SMIL (<animate> elements inside the SVG) animates everything including path morphing with zero JavaScript and plays even in <img> contexts. CSS keyframes cover the presentation properties with universal browser support and integrate with hover states, media queries, and scroll timelines. JS libraries (GSAP, anime.js, Lottie) scrub timelines, morph arbitrary paths, and replay After Effects animations, at the cost of a runtime.

TechniqueBrowser SupportAnimates Path d / MorphingAdded WeightBest For
SMIL (<animate>)Chrome, Firefox, Safari; not legacy Edge/IEYes, natively0 KB — markup inside the SVGSelf-contained icon animation in <img> or CSS backgrounds
CSS keyframesAll modern browsersVia CSS d property: Chromium, Firefox 97+, Safari 17.4+0.2-1 KB of rulesHover states, loops, entrance effects, scroll-driven reveals
GSAPAll, with runtimeYes (MorphSVG, paid plugin)~70 KB min, ~25 KB gzipped coreScrubbed timelines, sequenced narrative animation
Lottie (lottie-web)All, with runtimeYes — replays After Effects rigs~250 KB min player (~60 KB gz) + 20-150 KB JSONComplex character animation designed in After Effects

SMIL's obituary was written early and wrongly: Chrome declared it deprecated in 2015 and reversed the decision in 2016. It remains the only technique that animates an SVG referenced as an <img> with no page cooperation — which makes it the right choice for animated icons in markdown, email-adjacent contexts, and static sites. Its weakness is interaction: SMIL cannot respond to page events beyond its own begin-trigger syntax, so anything driven by scroll position, form state, or API data belongs in CSS or JS.

The trend worth watching is scroll-driven animation without JavaScript: animation-timeline: view() ties a keyframe animation to an element's scroll position, shipping in Chromium 115+ and under development elsewhere. A draw-on logomark that completes as it scrolls into view becomes pure CSS:

  • @supports (animation-timeline: view()) { .draw-on { animation-timeline: view(); animation-range: entry 10% cover 40%; } }

Wrap it in @supports so non-supporting browsers fall back to the timed animation instead of showing a blank stroke.

What Are the Performance Rules for Animated SVG Graphics?

Animate transform and opacity whenever the effect allows: these two properties are handled on the GPU compositor without triggering layout or paint, which keeps every frame inside the 16.7 ms budget of a 60 Hz display (8.3 ms on 120 Hz phones). Animating fill, stroke-dashoffset, filter, or path d forces main-thread repaint each frame — acceptable for one small icon, visibly janky for a 2,000-node illustration. If a traced artwork is that heavy, simplify it before animating it; the SVG optimization guide covers node reduction that typically cuts 50-70% of traced paths with no visible change.

Concrete habits: apply will-change: transform only to elements about to animate and remove it afterward, since each promotion costs GPU memory; never animate filter: drop-shadow() on complex paths (it repaints and re-blurs per frame — fade a pre-blurred duplicate's opacity instead); keep animated SVGs under roughly 100 simultaneous moving elements; and profile with DevTools' Performance panel watching for purple paint bars. On a mid-range Android, a full-viewport animated hero can burn 20-30% of frame budget before anything else renders.

Honoring prefers-reduced-motion

Respect the reduced-motion preference — about 35% of US adults over 40 show some vestibular dysfunction per NIH data, and large parallax or looping motion is what triggers it. One media query covers the whole document:

  • @media (prefers-reduced-motion: reduce) { .icon-pulse, .draw-on { animation: none; } .draw-on { stroke-dashoffset: 0; } }

Note the second rule: for the draw-on effect, cancelling the animation must still reveal the finished stroke, or reduced-motion users see an empty outline. WCAG 2.2 codifies the edges: Success Criterion 2.2.2 (Level A) requires a pause mechanism for auto-playing motion longer than 5 seconds, and 2.3.1 (Level A) bans anything flashing more than three times per second. Accessibility patterns for the rest of the graphic live in the SVG accessibility guide.

How Big Is an Animated SVG Compared to Video, GIF, or Lottie?

FormatTypical Size for a 3-5 s LoopTransparencyInfinite ScalingVerdict
Inline SVG + CSS keyframes2-30 KB total (compresses ~3:1 with gzip/brotli)YesYesDefault for logos, icons, illustrative motion under ~20 moving elements
Lottie JSON + lottie-web20-150 KB JSON + ~60 KB gzipped playerYesYesComplex After Effects rigs; heavy if used once
Animated GIF500 KB-5 MBBinary only, dithered edgesNoObsolete for motion graphics
WebM/MP4 video100 KB-2 MBWebM alpha yes, MP4 noNoPhotographic motion always wins on bytes here

The decision rule is element count, not aesthetic. Under ~20 independently moving shapes, SVG plus CSS is both smaller and sharper than any raster format, and it inherits text-quality rendering at every resolution and zoom level. Thousands of baked keyframes from a character rig justify Lottie's player cost. Photographic content — video backgrounds, product spins — belongs in WebM/AV1 where codecs exploit temporal redundancy that SVG cannot express. The format-vs-bytes tradeoffs mirror the static case in PNG vs SVG web performance.

One delivery detail matters more than the numbers: inline the SVG for page-controlled animation (build tools like svgr or a paste into the template), keep it as a file with an internal <style> block when the same animation is reused across contexts, and never load an animated SVG via <img> expecting page CSS to reach it — that combination silently renders frame one forever.

When Should You Not Animate an SVG?

Skip animation in four places. Fabrication files: laser and cutter importers (Glowforge, LightBurn, RDWorks) parse geometry, and <style> blocks or SMIL tags are dead weight at best — the SVG to PNG converter flattens a static frame when a raster preview is needed. Email: Gmail strips internal stylesheets and SVG support across clients is patchy, so animated email graphics are a GIF/video fallback problem regardless. Body-adjacent UI: looping motion near reading content competes with the text and violates the spirit of WCAG 2.2.2 even when legal. And low-end-device heroes: a full-viewport animated SVG on a 3-year-old budget phone is the most common real-world performance complaint in motion design.

When you do animate, make it earn its keep: explain a state change (loading, success, transition between views) or guide attention once on entrance. Decorative infinite loops are motion pollution — the eye is dragged to them involuntarily, and users cannot look away without leaving the page. If an animation cannot answer "what does this tell the user?", ship the static SVG; it is smaller, faster, accessible by default, and nobody has ever filed a bug report about a logo that sits still.

Frequently asked questions

How do I animate an SVG with CSS keyframes?

Put the SVG inline in your HTML (or keep a style block inside the SVG file), give the target element a class, and write standard @keyframes rules against it. Animate transform and opacity for compositor-speed performance, and always pair transforms with transform-box: fill-box; transform-origin: center — otherwise SVG rotates and scales around the canvas origin instead of the element's center. Page stylesheets cannot reach SVGs loaded via img tags.

Is SMIL animation dead?

No. Chrome declared SMIL deprecated in 2015 and reversed the decision in 2016; animate elements work in Chrome, Firefox, and Safari today. SMIL keeps one unique advantage: it animates an SVG even when the file is referenced by img or CSS background, with no JavaScript. Its weakness is interaction — anything driven by scroll position, page state, or user input is better handled by CSS keyframes or a library like GSAP.

Why does my SVG icon spin around the wrong point?

Because SVG transforms default to the canvas origin (0,0), not the element's center like HTML. Fix it with two declarations on the animated element: transform-box: fill-box, which makes transform-origin resolve against the element's own bounding box, and transform-origin: center. Both are supported in all current browsers. This single fix resolves the majority of broken SVG rotation and scale animations.

Does SVG animation hurt page performance?

Only if you animate paint-heavy properties. Transform and opacity run on the GPU compositor and cost almost nothing within the 16.7 ms frame budget of a 60 Hz display; fill, stroke-dashoffset, filter, and path d force main-thread repaints every frame and get janky on complex or large illustrations. Keep animated SVGs under roughly 100 moving elements, simplify heavy traced artwork first, and profile with the DevTools Performance panel.

How do I make SVG animations respect prefers-reduced-motion?

Wrap your animation rules in a media query: @media (prefers-reduced-motion: reduce) { .animated { animation: none; } }. Critically, also set the finished visual state inside that block — for stroke-draw effects, add stroke-dashoffset: 0 — so reduced-motion users see the completed graphic rather than a blank outline. The setting is exposed by macOS, Windows, iOS, and Android, and WCAG 2.2 requires pause controls for auto-playing motion over 5 seconds.

Sources

Convert files for this workflow

Try it on your own file

Drop in an image or an SVG and see the result before you pay. No signup is required to preview.