Skip to content

24 ways to impress your friends

Animating Vectors with SVG


Comments are ordered by helpfulness, as indicated by you. Help us pick out the gems and discourage asshattery by voting on notable comments.

Got something to add? You can leave a comment below.

Wray Bowling

This isn’t as clever as seeing how long each path is before defining how long its stroke segment will need to be.

There are, however, simpler ways to style paths. Use CSS!
In this version, I made a stroke array that was one part filled to beyond the length of any line (150%) and another unfilled segment also beyond any length (120%) then used offset to shift the filled part onto the whole.
In this version, the stroke array is 100% blank and a 0% stroked path that animates to a 0% blank and 100% stroked path.
Finally, in this variation, the blank space starts as a lot of smaller segments which are diminishing to zero while the stroked path is trying to reach 100% giving a “shimmer” effect.

Whether you use AnimationFrame, CSS Animation, or just as easily CSS Transitions, or the ancient and strange relic SMIL, I hope everyone hops on the SVG bandwagon soon. I’ve had a lot of fun with it this year already. It’s nice to know someone else is cranking on it. Thanks Brian

Steven Langbroek

I love this technique, but you basically forked this code straight over from Vox Media’s product-blog:

Chad Clark

Josh Riser, you can most definitely use .svg files as background images in CSS. If you use Modernizr, it is also very easy to write a Sass mixin to serve fallback images (.png, etc.) to less capable browsers.

Here’s a Gist of the mixin I use:


I’m trying to get this work with an external SVG file. So I used
“<use xlink:href=“images/sprites.svg#icon-undo”></use>” to call the external SVG and it actually shows the icon however the animation fails :( Is there a way to get this work?
Thank you!

Justin Avery

I love this new technique.

For those of you that prefer a drag and drop approach (not neccessarily the best approach, but certainly the quickest) then you should check out Lazy Line Painter –

I put together this codepen using that particular tool –

Raymond Uphoff aka myradon

@Josh you can say ‘background-image: url(“/path/to/image.svg”)’ You can even make some kind of SVG-spriting using target pseudo-class. Check this how-to:

I’ve fiddled with SVG dash-offset-animation too. I stopped because the project took to long, I couldn’t find time anymore. Personally I’m very pleased with the results check it at There were problems with going into an other MQ and some paths stopped animating. Also inserting 54 SVGs from an XML-file with Ajax is a bit slow.


Really like this technique!

To work the svg needs to be made up of path elements, have you got any tips/links explaining how to draw svg images that consist of path elements? When I use illustrator it always seems to want to make everything a polygon element…


Josh Riser

This is awesome. I would definitely jump on the bandwagon and start using SVGs, but for the most part I try to use CSS background-image to put an image anywhere, so as to not have img tags all over the site, loading various images and bogging down load times.

Is there a way to use SVGs in this manor?

Impress us

Be friendly / use Textile