Back to Learn SVG Animation

How SVG Line Drawing Animation Works

One of the most satisfying effects in SVG animation is the line drawing look — the moment when a path appears as if it is being drawn right in front of you. It feels clean, modern, and surprisingly elegant, which is why it shows up so often in logos, signatures, diagrams, icons, and explainer graphics. Under the hood, though, the idea is much simpler than it looks: SVG paths can have strokes, and those strokes can use dash patterns and offsets that you animate over time.

The basic idea

SVG line drawing animation usually works by taking a visible stroke and temporarily making it behave like one long dash that is shifted out of view. Then, by animating the dash offset back into place, the stroke gradually becomes visible, which creates the illusion that the line is being drawn. The two key SVG features behind this are stroke-dasharray, which defines the dash-and-gap pattern, and stroke-dashoffset, which shifts where that pattern starts rendering.

Why paths are often used

Most line drawing effects are built on <path> elements because a path is the most flexible shape in SVG. It can represent straight lines, curves, arcs, and complex illustrations, which makes it ideal for signatures, logos, and custom drawings. In practice, other SVG shapes can also use strokes, but paths are usually the most common choice when people talk about this effect.

What stroke-dasharray does

The stroke-dasharray value controls the pattern of dashes and gaps along the stroke. If you think of a normal dashed line, that is exactly the behavior this property defines. For a line drawing animation, developers often set the dash array to a value large enough to cover the whole path, so the stroke behaves like one long dash instead of many short ones.

What stroke-dashoffset does

stroke-dashoffset shifts the starting position of that dash pattern. If the dash is moved far enough, it can make the stroke appear hidden. When you animate the offset back toward zero, the dash slides into view, and the line appears to draw itself from one end to the other. That is the full trick. It is not really “drawing” in the literal sense; it is a stroke rendering effect created by changing dash positioning over time.

A simple example

Here is a basic example of the effect using CSS:

<svg width="220" height="80" viewBox="0 0 220 80">
  <path
    d="M10 40 Q 60 10, 110 40 T 210 40"
    class="draw-path"
  />
</svg>
.draw-path {
  fill: none;
  stroke: #111;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 300;
  stroke-dashoffset: 300;
  animation: drawLine 2s ease forwards;
}

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

This works because CSS animations let you define keyframes and animate property values over time, while SVG lets those stroke-related properties apply directly to the shape. The line starts with the dash offset pushed out, then the animation moves it back to zero.

Why the numbers matter

The effect works best when the dash array and dash offset are close to the real length of the path. If the values are too small, the line may appear only partially revealed. If they are large enough to cover the full length, the result looks like a clean draw-on animation. SVG also provides ways to work with path length more precisely: the pathLength attribute can calibrate distance calculations, and JavaScript can read an element’s actual length using getTotalLength().

Why people sometimes use JavaScript

For simple examples, hardcoded values often work fine. But if you are animating more complex artwork, JavaScript can help by measuring the exact path length with getTotalLength(). That lets you set the dash array and dash offset dynamically instead of guessing. It is especially useful when you are working with exported illustrations, longer signatures, or multiple paths of different lengths.

What makes the effect look good

The technique is technical, but the result is mostly about design choices. Stroke width changes the feel of the line. Rounded line caps can make the draw feel smoother. Easing affects whether the line feels mechanical or natural. And because CSS animations support timing controls and fill behavior, you can decide whether the drawing stays visible at the end or resets for a loop.

Common beginner mistakes

One common mistake is forgetting to remove the fill when you only want a drawn outline. Another is using dash values that do not match the path length well enough, which can make the effect look broken. A third is assuming the technique only works on hand-drawn illustrations, when in reality it works on many stroked SVG shapes and paths.

When to use SVG line drawing animation

This effect works especially well when you want to reveal something in a clear, elegant way. It is a natural fit for signatures, logos, route lines, technical diagrams, checkmarks, icons, and simple illustrations. Because SVG is web-native and CSS-friendly, the result can stay crisp and lightweight while still feeling polished.

Final thoughts

SVG line drawing animation looks impressive because it feels like illustration and motion happening at the same time. But the core mechanism is simple: define a stroked shape, turn the stroke into a dash pattern, push that pattern out of view with stroke-dashoffset, and animate it back. Once you understand that, the effect stops feeling magical and starts feeling usable.