SVG Line Draw
A route line and a check circle draw themselves with stroke-dashoffset; replay and change the duration.
AI prompt
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
<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>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.bx{width:min(320px,100%);display:grid;gap:10px}
svg{width:100%;height:auto;border-radius:12px;background:var(--surface);border:1px solid var(--line)}
.rt{fill:none;stroke:#171717;stroke-width:3;stroke-linecap:round;stroke-dasharray:1;stroke-dashoffset:0}
.st{fill:#171717}
.cr,.ck{fill:none;stroke:#ff5a36;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1;stroke-dashoffset:0}
.go .rt{animation:dr var(--d) cubic-bezier(.65,0,.35,1) both}
.go .cr{animation:dr calc(var(--d) * .43) ease-in-out both;animation-delay:var(--d)}
.go .ck{animation:dr calc(var(--d) * .25) ease-out both;animation-delay:calc(var(--d) * 1.43 + .15s)}
@keyframes dr{from{stroke-dashoffset:1}to{stroke-dashoffset:0}}
.row{display:flex;gap:12px;align-items:center;justify-content:space-between}
#rp{height:28px;padding:0 16px;border-radius:99px;border:0;background:var(--accent);color:var(--accent-ink);font-size:12px;font-weight:600;cursor:pointer}
label{display:flex;gap:8px;align-items:center;font-size:11.5px;color:var(--muted)}input[type=range]{accent-color:#171717;width:110px}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.go .rt,.go .cr,.go .ck{animation:none}}const bx=document.querySelector('.bx'),du=document.getElementById('du');
function play(){bx.style.setProperty('--d',(du.value/10)+'s');bx.classList.remove('go');void bx.offsetWidth;bx.classList.add('go');}
document.getElementById('rp').addEventListener('click',play);du.addEventListener('change',play);play();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SVG Line Draw — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.bx{width:min(320px,100%);display:grid;gap:10px}
svg{width:100%;height:auto;border-radius:12px;background:var(--surface);border:1px solid var(--line)}
.rt{fill:none;stroke:#171717;stroke-width:3;stroke-linecap:round;stroke-dasharray:1;stroke-dashoffset:0}
.st{fill:#171717}
.cr,.ck{fill:none;stroke:#ff5a36;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-dasharray:1;stroke-dashoffset:0}
.go .rt{animation:dr var(--d) cubic-bezier(.65,0,.35,1) both}
.go .cr{animation:dr calc(var(--d) * .43) ease-in-out both;animation-delay:var(--d)}
.go .ck{animation:dr calc(var(--d) * .25) ease-out both;animation-delay:calc(var(--d) * 1.43 + .15s)}
@keyframes dr{from{stroke-dashoffset:1}to{stroke-dashoffset:0}}
.row{display:flex;gap:12px;align-items:center;justify-content:space-between}
#rp{height:28px;padding:0 16px;border-radius:99px;border:0;background:var(--accent);color:var(--accent-ink);font-size:12px;font-weight:600;cursor:pointer}
label{display:flex;gap:8px;align-items:center;font-size:11.5px;color:var(--muted)}input[type=range]{accent-color:#171717;width:110px}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
@media (prefers-reduced-motion:reduce){.go .rt,.go .cr,.go .ck{animation:none}}
</style></head>
<body><div class="stage">
<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>
</div>
<script>
const bx=document.querySelector('.bx'),du=document.getElementById('du');
function play(){bx.style.setProperty('--d',(du.value/10)+'s');bx.classList.remove('go');void bx.offsetWidth;bx.classList.add('go');}
document.getElementById('rp').addEventListener('click',play);du.addEventListener('change',play);play();
</script>
</body></html>