Stockio

SVG Line Drawing Animation With stroke-dashoffset

Create SVG draw-on animations with normalized path lengths, reliable stroke timing, and static fallbacks that preserve meaningful artwork when motion is disabled.

By Aiko Tanaka

Motion Designer ·

On this page

An SVG draw-on effect works by moving a dash pattern along a stroked path. The line is not being constructed point by point; an existing stroke is progressively exposed. Understanding that model makes timing, multiple paths, and static fallbacks much easier to control.

Prepare artwork for a stroked reveal

Use paths with intentional stroke widths, line joins, and caps. A filled silhouette is not automatically suitable for line drawing: revealing its outline may not communicate the original shape. Decide whether the animation shows an illustration being sketched or merely exposes a decorative contour.

Minify a copy of the source, but preserve IDs, classes, and path structure that your animation needs. An optimizer can combine paths or rename hooks in ways that change sequencing. Keep the editable original and compare the optimized animation asset, not only its static appearance.

Use the svg minifier to prepare a static visual reference before tuning movement. Export the relevant values into your prototype and keep them fixed during the first timing comparison. This separates appearance decisions from playback behavior and makes changes easier to judge. The tool prepares the artwork or layout; the animation code still owns the timeline.

Define a baseline state that works without animation. Check that its content, controls, and status remain understandable when no intermediate frames are shown. A successful effect connects valid states; it does not hide essential information inside a brief moment that users must catch.

Normalize each path to a known length

The pathLength attribute can normalize distance calculations so a dash length of one represents the path's normalized length. Set pathLength to one on each targeted path and use unitless dash values. Percentage dash values use different reference behavior and should not be assumed to equal path length.

The example assumes inline SVG with a class on each path. It keeps the default stroke visible and applies the concealed starting position only when motion is allowed. For older or unusual rendering targets, verify how normalized dash distances behave before relying on this technique.

/* Target SVG paths must have pathLength="1". */
.draw-path {
fill: none;
stroke: currentColor;
stroke-dasharray: 1;
stroke-dashoffset: 0;
}
@media (prefers-reduced-motion: no-preference) {
.draw-path { animation: draw 900ms ease-out both; }
}
@keyframes draw {
from { stroke-dashoffset: 1; }
to { stroke-dashoffset: 0; }
}

Treat this example as a focused implementation pattern, not a complete component. Connect its selectors and lifecycle to your actual application state, and preserve the same outcome when playback is skipped. For terminology and API details, consult MDN’s stroke-dashoffset reference.

Sequence paths by meaning or length

A logo outline with many short segments can look noisy if every segment starts together. Choose a sequence policy: draw in reading order, group related strokes, or start all paths together with durations proportional to their lengths. None is automatically correct for every illustration.

For roughly constant drawing speed, longer paths need longer durations. getTotalLength can provide geometric lengths when scripting that calculation. Measure after the SVG is available and avoid recalculating lengths every frame. If the illustration changes responsively through CSS transforms, distinguish displayed size from underlying path length.

Use one-variable comparisons during review. Hold the distance constant while changing duration, then hold duration constant while changing the curve. Otherwise a reviewer may prefer the smaller movement rather than the timing change you intended to evaluate. Capture the chosen values beside the prototype so the production version does not rely on visual guesswork.

Related motion and animation guides can help place this effect in a wider motion vocabulary. Consistency should mean similar behavior for similar tasks, not forcing every component to travel the same distance or share one universal duration.

Keep labels and semantics independent

If the illustration communicates information, provide its ordinary accessible name and any necessary text explanation. The line animation should not be the only way to discover a chart trend or process order. Decorative artwork can remain hidden from assistive technology while nearby text communicates the real message.

Do not repeatedly redraw a meaningful diagram while someone is reading it. A one-time reveal is often easier to follow than a perpetual erase-and-redraw loop. Under reduced motion, show the finished drawing immediately. Removing the keyframes should never leave all the paths invisible.

Review the relevant platform behavior in MDN’s pathLength reference. Where support is incomplete, prefer an immediately usable final state over a complicated fallback that introduces its own timing bugs. Feature detection should gate the enhancement, not access to the underlying task.

Inspect stroke edges and replay behavior

Rounded line caps can leave a small visible dot at the supposedly hidden start. Look at the exact first frame rather than assuming a full dash offset means nothing can be seen. Consider opacity during the initial frame if the cap artifact matters, and verify the transition to the visible stroke.

Test replay after resizing, late asset loading, and navigation away from the element. If JavaScript starts the effect, use an explicit replay policy rather than toggling classes in a way that depends on forced layout. Check that optimized SVG output still preserves every selector and normalized length attribute.

Run a production-content pass after the isolated demo succeeds. Use long labels, realistic images, narrow containers, and enough neighboring elements to expose overlap. Repeat with keyboard navigation and at least one touch device. A demonstration that works only when the pointer stays still is not a reliable interaction.

Record a short before-and-after trace using the guidance in web.dev’s animation guide. Compare the same interaction with motion enabled and disabled. Look for repeated layout, large paint regions, and delayed input rather than judging performance solely from a smooth recording on a powerful development machine.

Keep a concise acceptance note with the trigger, final state, cancellation policy, and reduced-motion behavior. The broader development collection is useful for implementation context, but the acceptance note should be specific enough that another developer can reproduce this effect without watching a video.

Key takeaways

  • Reveal strokes, not arbitrary filled artwork.
  • Normalize path distances and avoid confusing percentages with lengths.
  • Sequence paths intentionally and preserve optimization hooks.
  • Show the complete illustration when animation is unavailable.
Featured sponsor

Reach designers & developers at work

Put your product next to the tools people use every day. One sponsor per placement, no tracking pixels.

Become a sponsor

Keep reading

Related articles

More in Motion & Animation
Motion & Animation

Rive vs Lottie vs CSS: Choosing Animation Tools

Compare CSS, Lottie, and Rive by interaction model, delivery cost, accessibility, and handoff requirements, then choose the smallest reliable system for your product animation.

Includes: SVG minifierAiko TanakaAiko Tanaka
Icons & Illustration

10 Best Free SVG Sites for Web Graphics

Find free SVGs for backgrounds, patterns, maps, and illustrations, with practical notes on each site's strengths, licensing, and how to pick files that suit your project.

Includes: SVG minifierMateo FernándezMateo Fernández
Icons & Illustration

20 Best Free Icon Sets for Websites and Apps

Compare twenty free icon families, from crisp interface line art to brand logos and variable symbols, then choose a consistent set for your website, app, or design file.

Includes: SVG minifierAiko TanakaAiko Tanaka
Branding & Business

How to Organize Design Assets: Icons, Fonts and Mockups

Create a searchable asset library with clear naming, license records, source files, and optimized exports so every icon, font, and mockup is ready to reuse.

Includes: SVG minifierPiotr KowalskiPiotr Kowalski
Branding & Business

One-Color and Reversed Logo Versions for Production

Adapt a full-color logo for single-ink printing, dark backgrounds, embroidery, and engraving while preserving shape recognition and avoiding muddy automatic conversions.

Includes: SVG minifierArjun RamanArjun Raman
Branding & Business

Logo File Formats to Deliver: SVG, PDF, PNG and Source

Prepare a practical logo delivery package with vector masters, web-ready SVGs, transparent PNGs, print PDFs, and an asset index that prevents expensive format mistakes.

Includes: SVG minifierPiotr KowalskiPiotr Kowalski