Skip to main content
SP

SVG Path Animator

Animate SVG paths with the stroke-dasharray technique — draw lines, shapes, and icons that trace themselves onto the screen.

Did you like the tool? Thanks!
Share:

More CSS Tools


    

How to Use SVG Path Animator

Create the classic SVG line-drawing animation effect — where a path appears to draw itself stroke by stroke — using the time-tested stroke-dasharray and stroke-dashoffset CSS technique. Paste or type an SVG path definition into the textarea, or click one of five preset shapes (Heart, Star, Arrow, Checkmark, Circle) to populate it. Set the SVG viewBox dimensions, pick a stroke colour and width, choose the animation duration and easing curve, then click Play Animation to watch the path trace itself. Toggle the Loop switch to make the animation repeat continuously. The tool outputs the CSS animation class with the correctly calculated dasharray/dashoffset values and the @keyframes draw definition — plug it into any SVG element to get the same line-drawing effect.

About SVG Path Animator

SVG line-drawing animation is one of the most satisfying visual effects on the web, and it is achieved with a surprisingly simple CSS trick that has become an industry standard technique. The effect requires no JavaScript libraries, no canvas API, and no complex maths — just two CSS properties and a single @keyframes rule. Understanding how it works reveals the elegance of SVG's vector model and the power of CSS animation when applied to presentation attributes. The key to the technique lies in two SVG stroke properties: `stroke-dasharray` and `stroke-dashoffset`. The dasharray property defines a pattern of dashes and gaps for the stroke — for example, `stroke-dasharray: 10 5` means a 10-unit dash followed by a 5-unit gap, repeating. But if you set `stroke-dasharray` to a single value equal to (or larger than) the total length of the SVG path, and set `stroke-dashoffset` to that same value, the entire stroke is "hidden" because the offset pushes the dash pattern past the visible portion of the path. Animating the dashoffset from that maximum value down to zero brings the dash back into view, starting from the beginning of the path and progressing to the end — and because a single dash covers the entire path, this creates the illusion that the path is being drawn in real time. In practical terms, the CSS looks like this: ```css .svg-path { stroke-dasharray: 500; stroke-dashoffset: 500; animation: draw 2s ease forwards; } @keyframes draw { to { stroke-dashoffset: 0; } } ``` When you apply this to an SVG `<path>` element, the browser animates the stroke-dashoffset from 500 to 0 over 2 seconds, and the stroke appears to trace along the path. The magic number 500 is the approximate length of the path — it works as long as the dasharray value is greater than the actual path length (any excess is simply invisible beyond the end of the path). For a truly precise implementation, you would use the JavaScript method `path.getTotalLength()` to get the exact path length and use that as the dasharray/offset value. This tool does exactly that in the preview so the animation is always accurate regardless of the path data you provide. The beauty of this technique is that it works on any SVG path, no matter how complex. A simple straight line draws in a single smooth motion. A cursive signature traces every letterform. An intricate logo with nested paths draws each curve in sequence (when applied individually to each path). A geometric pattern reveals itself line by line. The technique is resolution-independent because SVGs scale natively, so the animation looks sharp at any size, on any screen. Why use a tool for this instead of writing the CSS directly? The challenge is that the dasharray value must be manually set to a number larger than the path length, and getting the path length requires either measuring manually (tedious and error-prone) or using JavaScript (inconvenient). The tool removes this guesswork — you paste the path data, and the preview calculates the real path length, sets the correct dasharray/offset, and shows you the result. If you adjust the stroke width or colour, the preview updates instantly. If you change the animation duration or easing, you see the effect immediately. The five preset shapes provide ready-to-use SVG paths that demonstrate common use cases. The Heart path is a classic icon suitable for like buttons or favicons. The Star is a five-pointed star shape useful for ratings or decorative accents. The Arrow shows a simple chevron or direction indicator — great for scroll-down hints or navigation cues. The Checkmark is a smooth tick symbol perfect for success states and form validation. The Circle is perhaps the most instructive: drawing a circle stroke-by-stroke demonstrates how the technique handles closed paths, where the dashoffset starts at the top (12 o'clock position) and progresses clockwise. Performance of this technique is excellent. The CSS animation runs on the compositor thread because it only changes the `stroke-dashoffset` presentation attribute, which does not trigger layout or paint. SVGs themselves can be hardware-accelerated when they are relatively small and simple (under a few hundred path commands). For very large or complex SVGs with hundreds of path elements, rendering may become CPU-bound, but the animation itself adds trivial overhead. One useful optimisation: apply `will-change: stroke-dashoffset` to the animated path, which hints to the browser to promote the element to a GPU layer before the animation starts. Browser support for animating stroke-dashoffset is universal — it works in Chrome, Firefox, Safari, Edge, and even Internet Explorer 11 (though IE may require the SVG to have explicit `width` and `height` attributes rather than relying on CSS). The @keyframes rule for the animation is also universally supported. The tool generates standards-compliant CSS that works on any browser released in the last decade. Use cases go far beyond decorative effects. Loading spinners made of animated SVG circles are used on thousands of websites. Progress indicators that draw a circular or linear path as a task progresses. Animated logos that reveal themselves on a loading or splash screen. Interactive diagrams where the user clicks a "Reveal" button and sees the structure drawn step by step. Educational illustrations where each line appears as the accompanying text is read. Signature animations on testimonials or personal portfolio pages. The technique is versatile enough to cover all of these with the same simple CSS.

Details & Tips

Calculating the exact path length and using it for the animation: ```javascript var path = document.querySelector('.svg-path'); var length = path.getTotalLength(); path.style.strokeDasharray = length; path.style.strokeDashoffset = length; ``` The `getTotalLength()` method returns the computed length of the path in user units (the coordinate system defined by the SVG\'s viewBox). This value is what you should use for both the dasharray and the initial dashoffset. The CSS @keyframes then animates dashoffset from this value to 0. For SVGs with multiple sub-paths (a single path with a `M ... Z M ... Z` structure), `getTotalLength()` returns the sum of all sub-path lengths. The animation draws all sub-paths simultaneously rather than sequentially. For sequential drawing of separate paths, you would apply the animation to each `<path>` element individually, possibly with staggered animation-delay values. **Preset SVG paths provided by the tool:** - **Heart:** A classic heart silhouette using two cubic Bezier curves. The path uses relative coordinates for compactness and symmetry. - **Star:** A five-pointed star defined with alternating outer and inner radius points, connected by lines. - **Arrow:** A right-pointing chevron made of two line segments meeting at an apex. - **Checkmark:** A smooth checkmark made of two connected line segments with slightly rounded joins. - **Circle:** A circle defined using two semi-circular arcs (or a single full-circle arc command). **Stroke appearance properties:** The tool lets you control `stroke` (colour), `stroke-width` (thickness), `stroke-linecap` (butt, round, or square end caps), and `stroke-linejoin` (miter, round, or bevel corner joins). Round linecaps are recommended for the line-drawing effect because they create a smooth, pen-like appearance at the advancing tip of the stroke. Square or butt caps can look abrupt at the leading edge. **Easing curves for the draw animation:** `ease-out` is the most natural because it creates the sensation of a pen accelerating from a stopped position and then settling smoothly. `linear` gives a mechanical, constant-speed tracing — appropriate for technical diagrams or progress indicators where predictability matters more than organic feel. `ease` (the default) works reasonably well for most paths. `ease-in` causes the stroke to start slowly and speed up, which can look like the pen is "gathering speed" — an unusual but occasionally striking choice. **Looping the animation:** When Loop is enabled, the animation uses `animation-iteration-count: infinite` and `animation-direction: alternate`. The forward iteration draws the path (dashoffset goes from max to 0), and the reverse iteration undraws it (dashoffset goes from 0 back to max), creating a continuous draw-undraw cycle. For a continuous draw-only loop (the stroke completes and then instantly starts over), use infinite iteration with direction: normal — but note that the reset is instantaneous, not animated, unless you add a second @keyframes step. **Browser compatibility notes:** The stroke-dasharray and stroke-dashoffset CSS properties (and their SVG presentation attribute equivalents) are supported in all current browsers. `getTotalLength()` is supported in all browsers that support SVG (IE9+, and all modern browsers). The main compatibility concern is not the technique itself but the SVG rendering: IE11 does not support CSS transforms on SVG child elements well, so if you are wrapping the animated SVG in a scaled container, test on IE11. For modern evergreen browsers, the technique is 100% reliable.

Frequently Asked Questions

How does the SVG line-drawing animation technique work?
It uses two SVG stroke properties: `stroke-dasharray` set to the path length (or larger) creates a single dash covering the entire path, and `stroke-dashoffset` set to the same length hides that dash. Animating `stroke-dashoffset` from the path length down to 0 reveals the stroke progressively, creating the illusion that the path is being drawn.
What is stroke-dasharray?
Stroke-dasharray is an SVG/CSS property that controls the pattern of dashes and gaps in a stroke. For example, `stroke-dasharray: 10 5` means a 10-unit dash followed by a 5-unit gap. When set to a single value larger than the path length, the entire stroke becomes one continuous dash.
What is stroke-dashoffset?
Stroke-dashoffset shifts the starting position of the dash pattern along the path. A positive offset moves the pattern backward, effectively hiding the beginning of the stroke. Animating stroke-dashoffset from a large value to 0 is what creates the line-drawing effect.
How do I get the exact length of an SVG path?
The JavaScript method `pathElement.getTotalLength()` returns the exact computed length of the path in SVG user units. This tool uses that method in the preview to calculate the correct dasharray and dashoffset values automatically. For production use, you would call `getTotalLength()` on each path you want to animate.
What preset SVG shapes does the tool provide?
Five presets: Heart (a classic heart icon), Star (five-pointed star), Arrow (right-pointing chevron), Checkmark (smooth tick symbol), and Circle (full circle). Click any preset to populate the path textarea with that shape's path data, then customise the stroke colour, width, and animation.
Can I paste my own SVG path data?
Yes — the path textarea accepts any valid SVG path `d` attribute string. You can copy the `d` attribute from any SVG file or vector editing tool (Illustrator, Figma, Inkscape) and paste it in. The tool will calculate the path length and generate the animation CSS.
What should the dasharray value be set to?
Set it to the exact length of your path (from `getTotalLength()`) for a precise animation where the stroke begins drawing at time 0 and finishes exactly at the end of the animation. Setting it higher than the path length also works — the excess is simply beyond the end of the visible path and has no effect.
How do I animate multiple paths in sequence?
Apply the generated CSS class to each `<path>` element in your SVG and give each one a different `animation-delay`. For example, path 1 gets `animation-delay: 0s`, path 2 gets `animation-delay: 0.5s`, path 3 gets `animation-delay: 1s`. The delays create a staggered drawing effect.
What stroke-linecap is best for the drawing effect?
Use `stroke-linecap: round` — it gives the advancing tip of the stroke a rounded, pen-like appearance that looks natural as the line draws. The `butt` value creates a flat, abrupt leading edge, and `square` is similar but extends slightly. Round caps are universally preferred for line-drawing animations.
Does the animation work with filled SVG shapes?
The stroke-dasharray technique only animates strokes, not fills. If your SVG path has a `fill` colour, the fill will be visible from the start — the stroke draws over it. For a pure line-drawing effect, set `fill: none` (or `fill: transparent`) on the path so only the stroke is visible.
Can I loop the drawing animation continuously?
Yes — toggle the Loop switch. The animation uses `animation-iteration-count: infinite` with `animation-direction: alternate` to continuously draw and undraw the path. Without alternate direction, the path draws and then jumps to the start instantly.
Is my data sent to a server?
No — all SVG path processing, length calculation, and CSS generation happens locally in your browser. Your SVG data never leaves your device.

Part of These Collections

Also Available As

svg path animator, svg line drawing, stroke dasharray animation, svg stroke animation, svg drawing effect, svg path animation, stroke dashoffset, svg icon animation, animated svg, svg line animation, draw svg path

Found a Problem?

Let us know if something with SVG Path Animator isn't working as expected.

Thanks — we'll take a look.