Skip to content
IndexRequest a UIAboutContact

SVG Line Draw

A route line and a check circle draw themselves with stroke-dashoffset; replay and change the duration.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a self-drawing SVG illustration: a winding route line from a start dot to a destination pin across a light card, followed by a circle that draws around a check mark at the destination. Use stroke-dasharray and stroke-dashoffset with pathLength set to 1 so each path animates from 1 to 0. The route draws in 1.4 seconds with an ease-in-out curve, the circle in 0.6 seconds, and the check mark 150 milliseconds after the circle completes. Round line caps, near-black route, accent orange circle and check. Provide a Replay button and a Duration slider from 0.6 to 3 seconds. prefers-reduced-motion shows the finished drawing. Inline SVG, plain CSS and JavaScript, no libraries.

About this pattern

Definition

Line drawing animates a path from nothing to complete by moving its dash offset. The line appears to be drawn by an invisible pen, which is ideal for icons, maps and logo reveals.

Purpose & UX principles

  • Draws attention to a path (a route, a growth line) and makes success states feel earned.
  • Normalise the path length (pathLength="1") so one animation works for any path.
  • Stagger multiple paths and keep total time under about two seconds.

Interaction states

  • Hidden, drawing, complete; Replay restarts; Duration slider changes the speed.

Motion specification

  • Each path draws with ease-in-out; the circle starts at 0 and the check follows 150ms after the circle finishes.
  • Reduced motion: the finished drawing is shown immediately.

Responsive behaviour

  • SVG scales with the container; stroke width stays visible with vector-effect non-scaling-stroke if the icon is resized a lot.
  • Provide the final drawn state for print and reduced-motion users.

Code

HTML
<div class="bx"><svg viewBox="0 0 300 120" aria-hidden="true"><path class="rt" id="rt" pathLength="1" d="M20 96C60 96 70 40 110 44S160 98 196 84S238 40 262 34"/><circle class="st" cx="20" cy="96" r="4"/><circle class="cr" id="cr" pathLength="1" cx="262" cy="34" r="16"/><path class="ck" id="ck" pathLength="1" d="M254 34l6 6 11-12"/></svg>
<div class="row"><button id="rp" type="button">Replay</button><label>Duration <input id="du" type="range" min="6" max="30" value="14"></label></div></div>

Related patterns

Animated Checkmark Button

↗
Animated Checkmark ButtonMicro Interactions

Staggered Entrance

↗
Staggered EntranceMotion & Transitions

Easing Comparison

↗
Easing ComparisonMotion & Transitions