Skip to content

SVG Animation

SVG animation, with no library and no Lottie runtime.

A logo that draws itself, an icon that reacts to hover, a spinner that ships nothing extra — vector graphics animate themselves, because the geometry is already addressable. What follows is which technique to use where, and what each one costs.

draw-onstroke-dashoffset

A live animation, not a recording — and it holds still for anyone who has asked for reduced motion.

Six steps

How to animate an SVG.

Two decisions come before any keyframe: what the elements are called, and how the file gets onto the page. Both are cheap now and expensive to change once the animation exists.

  1. 01

    Give the thing you want to move an id

    An animation targets a selector. A drawing of forty anonymous paths gives you nothing to select, so naming comes before motion — not as tidiness, as a prerequisite.

  2. 02

    Decide how the file reaches the page

    Inline in the document, or loaded through an <img> or background-image? Inline means page CSS and JavaScript can reach it. Loaded as a resource, it is isolated and only what is inside the file will run.

  3. 03

    Pick the cheapest property that gets the effect

    Transform and opacity are handled by the compositor and cost almost nothing. Geometry attributes force a re-layout every frame. Reach for the expensive ones only when nothing else does the job.

  4. 04

    Write the keyframes

    For a draw-on, set stroke-dasharray to the path length, stroke-dashoffset to the same value, then animate the offset to zero. For a loop that must survive an <img> tag, use SMIL instead.

  5. 05

    Give reduced motion a still fallback

    Wrap decorative motion in a prefers-reduced-motion query and define the resting state explicitly. Three lines, and it matters to anyone who gets motion sick from a looping graphic.

  6. 06

    Check it where it will actually live

    The same file can animate in the document and sit frozen in an <img> on the next page. Test the delivery method, not just the file.

Four techniques

Which one depends on how the file is delivered.

The deciding question is almost never aesthetic. It is whether the SVG is inline in the document or loaded as a separate resource.

CSS keyframes

External stylesheet or a <style> block inside the SVG

Best for

Almost everything. Transforms, opacity, fills, stroke-dashoffset — with hover and media queries available.

Limits

Only works on an inline SVG or one with its styles embedded. An SVG loaded through <img> is isolated from page CSS.

SMIL (<animate>)

Elements inside the SVG itself

Best for

Self-contained files that must animate anywhere, including inside an <img> tag or an email client that allows it.

Limits

Declarative and awkward to sequence. Support is good in modern browsers but it is a dead-end spec.

Web Animations API

JavaScript

Best for

Anything driven by state — scroll position, a click, data arriving. Full playback control.

Limits

Needs JavaScript, so nothing animates before hydration.

CSS transitions

Stylesheet, on hover or a class change

Best for

Micro-interactions: an icon that shifts colour or nudges on hover. Cheapest thing on this list.

Limits

Two states only. Anything with a middle needs keyframes.

The two you will actually write

Draw-on, and a self-contained loop.

CSS keyframesinline SVG
#stem {
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: draw 2s ease forwards;
}

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #stem {
    animation: none;
    stroke-dashoffset: 0;
  }
}
SMILworks in <img>
<g id="badge">
  <circle r="20" fill="#F25C05"/>
  <animateTransform
    attributeName="transform"
    type="rotate"
    from="0" to="360"
    dur="8s"
    repeatCount="indefinite"/>
</g>

Both target an element by ID. That is the practical reason named layers matter: animating #stem is possible, animating the fourth anonymous path is not.

Cost of each property

Six properties, from free to expensive.

Animatable SVG properties with rendering cost
PropertyCostNotes
transformCheap — compositor onlyMove, rotate and scale groups. Set transform-box and transform-origin or it rotates about the wrong point.
opacityCheap — compositor onlyFades and cross-dissolves between states.
stroke-dashoffsetModerateThe draw-on effect. Set dasharray to the path length and animate offset to zero.
fill / strokeModerateColour transitions. Reference a CSS variable and one change repaints the whole drawing.
d (path data)ExpensiveTrue shape morphing. Only interpolates when both paths have the same command structure.
x / y / widthExpensive — triggers layoutPrefer a transform. Animating geometry attributes forces a re-layout every frame.

SVG, Lottie, GIF, video

Four ways to put motion on a page.

The honest split is by what the motion is. Interface behaviour belongs in SVG; a character walking across the screen probably does not.

SVG + CSS or SMIL

runtime: None

Good at

Interface motion: draw-on logos, icon micro-interactions, spinners, state changes. Scales to any size and the text inside stays real text.

Bad at

Hand-authoring complex character animation is miserable. There is no timeline unless you bring a tool.

Lottie

runtime: A JavaScript player you ship

Good at

Complex, keyframe-heavy motion exported straight out of After Effects. This is what it is genuinely better at.

Bad at

It is JSON plus a runtime, so nothing moves before the script loads, and you need the After Effects pipeline to author it.

Animated GIF

runtime: None

Good at

Works anywhere, including places that strip scripts. No integration work at all.

Bad at

Raster, so it blurs when scaled; a fixed frame rate, a limited palette, and file sizes far past anything vector needs.

Video

runtime: The video element

Good at

Photographic or filmed motion, where vector is the wrong tool entirely.

Bad at

Heavy, autoplay is restricted on mobile, and a flat rectangle cannot inherit your theme colours.

If you want a timeline

This page is a reference, not an animation editor.

There is no timeline here and nothing on this site generates motion — what we produce is static geometry with named groups, which is the thing an animation needs to exist first. When you would rather drag keyframes than write them, these are the tools.

SVGator

A timeline editor in the browser — keyframes, morphing, motion paths, click and hover triggers, and an export that carries the animation in the file.

SVG Artista

Free and single-purpose: paste an SVG, get the stroke and fill draw-on animation written out as CSS you can copy. The fastest route to the effect in the hero above.

GSAP

The library for anything sequenced or scroll-driven, with SVG-specific plugins for morphing, drawing and dragging. Reaches for JavaScript where the others stop.

Motion

Declarative animation for React, including path drawing and morphing, if the SVG is already a component in your tree.

Questions

What SVG animation is, and what it costs.

What is an SVG animation?
It is motion described inside a vector file, or applied to one, rather than recorded as frames. Because every shape in an SVG is an element in the document, you can change its position, colour, opacity or outline over time the same way you would animate anything else on a page — and the result stays sharp at any size.
Is an animated SVG possible?
Yes, three ways: CSS keyframes, SMIL elements written inside the file, and the Web Animations API from JavaScript. All three are native to the browser, so none of them needs a player library shipped alongside.
Can AI make SVG animations?
Not here, and it is worth being specific about why. Our generator produces static vector geometry — shapes, paths and named groups — and the motion is something you add afterwards in CSS or SMIL. What generation does contribute is the part that usually blocks animation: a drawing whose pieces already carry ids, so there is something to select.
What is the difference between SVG animation and Lottie?
An animated SVG runs on the browser's own animation engine with nothing else shipped. Lottie is JSON plus a JavaScript player, authored in After Effects, and it is genuinely better at complex keyframe-heavy motion. For interface work — a logo drawing on, an icon reacting to hover, a spinner — SVG does it with no runtime at all.
Does animation work when the SVG is in an img tag?
Only if the animation is inside the file — SMIL, or CSS in an embedded style block. An SVG loaded through img is isolated from the page's stylesheet, so external CSS cannot reach it.
How does the draw-on line effect work?
Set stroke-dasharray to the total length of the path so the dash covers it entirely, set stroke-dashoffset to that same value so the dash sits off-screen, then animate the offset to zero. The line appears to draw itself.
Can I morph one shape into another?
Yes, by animating the d attribute — but only when both path strings have identical command sequences and point counts. Otherwise the browser has no correspondence between the two shapes and simply snaps.
What about reduced motion?
Wrap decorative animation in a prefers-reduced-motion media query and give it a still fallback. It costs three lines and it matters to people who get motion sick from looping graphics.
Is SVG animation good for performance?
Transform and opacity are handled by the compositor and are effectively free. Animating path data or geometry attributes is far more expensive, and animating many nodes at once is the thing that actually drops frames.
Can I animate artwork generated here?
Yes, though you write the animation yourself — there is no timeline editor on this site. What generation gives you is the precondition: named groups, so you target #stem rather than hunting for the fourth anonymous path. SVGator and SVG Artista are the tools to reach for if you would rather not hand-write the keyframes.

Named groups now. Motion later.

Generate artwork