Home / Learn / How to make an SVG line draw itself

How to make an SVG line draw itself

A line that draws in front of the viewer, good for logos, signatures and arrows.

Steps

  1. Set stroke-dasharray to the path length.
  2. Start with stroke-dashoffset at the same length.
  3. Animate the offset to zero.

The code

path{fill:none;stroke:#ff5e1a;stroke-width:4;stroke-dasharray:300;stroke-dashoffset:300;animation:draw 2.4s ease-in-out forwards}
@keyframes draw{to{stroke-dashoffset:0}}

Want ready-made variations? The library has hundreds, each with standalone code.