Route Path Draw on Map
A route drawn across a simple map with a pin travelling along it, a scrub slider and distance and time readouts.
AI prompt
Clean flat map illustration of a small neighbourhood with pale blocks, a river and a park, a bold blue route line curving from a green start marker labelled A to a red end pin labelled B, the route partly drawn with a round pin at the current position, small info chip near the pin reading 2.4 km and 9 min, soft grey streets, light theme, flat modern style. Negative: real map labels, logos, clutter, text errors. Reduced motion: static design.About this pattern
Definition
Animating a route helps people understand a journey: where it starts, where it turns and how long it takes. The line is a single SVG path drawn with stroke-dashoffset, and a pin follows it using getPointAtLength so it stays exactly on the line, even around curves.
When to use it
- Use one path for the route and set pathLength or read getTotalLength to drive the animation.
- Place the pin with getPointAtLength(progress * length) and rotate it by sampling a point just ahead.
- Show start and end markers and update distance and time from the same progress value.
- Offer a scrub slider so the viewer can control the pace.
What the controls do
- Play, replay and a Progress slider to scrub.
Motion & timing
- The trip animates over 5 seconds.
- Reduced motion: no autoplay; use the slider.
Tips & variations
- Provide the route description in text for people who cannot see the map.
- Do not use colour alone; label start and end.
Code of this live preview
<div class="bx"><svg class="mp" viewBox="0 0 300 130" role="img" aria-label="Route from A to B across a simple map"><rect width="300" height="130" fill="#eef1ec"/><path d="M0 92 C60 80 90 110 150 98 S250 70 300 84 V130 H0Z" fill="#cfe3f2"/><rect x="190" y="14" width="80" height="40" rx="8" fill="#d9ebcf"/><g fill="#fff"><rect x="14" y="14" width="46" height="30" rx="4"/><rect x="70" y="14" width="46" height="30" rx="4"/><rect x="14" y="54" width="46" height="26" rx="4"/><rect x="126" y="14" width="54" height="30" rx="4"/></g><path id="rt" d="M24 64 C60 64 70 50 94 50 S130 62 150 58 S170 30 200 34 S240 60 276 36" fill="none" stroke="#c7d3f6" stroke-width="6" stroke-linecap="round"/><path id="rd" d="M24 64 C60 64 70 50 94 50 S130 62 150 58 S170 30 200 34 S240 60 276 36" fill="none" stroke="#2f6bff" stroke-width="6" stroke-linecap="round" pathLength="1" stroke-dasharray="1" stroke-dashoffset="1"/><circle cx="24" cy="64" r="6" fill="#1f9d55"/><text x="24" y="82" font-size="9" text-anchor="middle" fill="#333" font-family="system-ui">A</text><text x="276" y="28" font-size="9" text-anchor="middle" fill="#333" font-family="system-ui">B</text><circle id="pn" r="7" fill="#fff" stroke="#2f6bff" stroke-width="3"/></svg><label class="rw">Progress <b id="pv">0%</b><input id="ps" type="range" min="0" max="100" value="0"></label><div class="two"><button class="mini" id="pl" type="button">Play</button><p class="out" id="out"></p></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}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.mp{width:100%;height:auto;border-radius:12px;border:1px solid var(--line);display:block}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}.out{font-size:12px;color:var(--muted);min-height:16px;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const rt=document.getElementById('rt'),rd=document.getElementById('rd'),pn=document.getElementById('pn'),ps=document.getElementById('ps'),pl=document.getElementById('pl'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches,L=rt.getTotalLength();let raf=0,run=false;
function set(v){const pt=rt.getPointAtLength(v*L);pn.setAttribute('cx',pt.x);pn.setAttribute('cy',pt.y);rd.style.strokeDashoffset=1-v;ps.value=Math.round(v*100);document.getElementById('pv').textContent=Math.round(v*100)+'%';document.getElementById('out').textContent=(v*2.4).toFixed(1)+' of 2.4 km \u00b7 '+Math.round(9*(1-v))+' min left';}
function play(){cancelAnimationFrame(raf);if(run){run=false;pl.textContent='Play';return;}let v=+ps.value/100;if(v>=1)v=0;run=true;pl.textContent='Pause';let last=performance.now();(function f(n){v=Math.min(1,v+(n-last)/5000);last=n;set(v);if(v<1&&run)raf=requestAnimationFrame(f);else{run=false;pl.textContent=v>=1?'Replay':'Play';}})(last);}
pl.addEventListener('click',play);ps.addEventListener('input',()=>{run=false;cancelAnimationFrame(raf);pl.textContent='Play';set(ps.value/100);});set(calm?.55:0);if(!calm)setTimeout(play,400);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>Route Path Draw on Map — 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}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.mp{width:100%;height:auto;border-radius:12px;border:1px solid var(--line);display:block}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.mini{height:30px;padding:0 14px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:12px;font-weight:600;cursor:pointer}.mini:disabled{opacity:.4;cursor:default}.out{font-size:12px;color:var(--muted);min-height:16px;margin:0}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><svg class="mp" viewBox="0 0 300 130" role="img" aria-label="Route from A to B across a simple map"><rect width="300" height="130" fill="#eef1ec"/><path d="M0 92 C60 80 90 110 150 98 S250 70 300 84 V130 H0Z" fill="#cfe3f2"/><rect x="190" y="14" width="80" height="40" rx="8" fill="#d9ebcf"/><g fill="#fff"><rect x="14" y="14" width="46" height="30" rx="4"/><rect x="70" y="14" width="46" height="30" rx="4"/><rect x="14" y="54" width="46" height="26" rx="4"/><rect x="126" y="14" width="54" height="30" rx="4"/></g><path id="rt" d="M24 64 C60 64 70 50 94 50 S130 62 150 58 S170 30 200 34 S240 60 276 36" fill="none" stroke="#c7d3f6" stroke-width="6" stroke-linecap="round"/><path id="rd" d="M24 64 C60 64 70 50 94 50 S130 62 150 58 S170 30 200 34 S240 60 276 36" fill="none" stroke="#2f6bff" stroke-width="6" stroke-linecap="round" pathLength="1" stroke-dasharray="1" stroke-dashoffset="1"/><circle cx="24" cy="64" r="6" fill="#1f9d55"/><text x="24" y="82" font-size="9" text-anchor="middle" fill="#333" font-family="system-ui">A</text><text x="276" y="28" font-size="9" text-anchor="middle" fill="#333" font-family="system-ui">B</text><circle id="pn" r="7" fill="#fff" stroke="#2f6bff" stroke-width="3"/></svg><label class="rw">Progress <b id="pv">0%</b><input id="ps" type="range" min="0" max="100" value="0"></label><div class="two"><button class="mini" id="pl" type="button">Play</button><p class="out" id="out"></p></div></div>
</div>
<script>
const rt=document.getElementById('rt'),rd=document.getElementById('rd'),pn=document.getElementById('pn'),ps=document.getElementById('ps'),pl=document.getElementById('pl'),calm=matchMedia('(prefers-reduced-motion:reduce)').matches,L=rt.getTotalLength();let raf=0,run=false;
function set(v){const pt=rt.getPointAtLength(v*L);pn.setAttribute('cx',pt.x);pn.setAttribute('cy',pt.y);rd.style.strokeDashoffset=1-v;ps.value=Math.round(v*100);document.getElementById('pv').textContent=Math.round(v*100)+'%';document.getElementById('out').textContent=(v*2.4).toFixed(1)+' of 2.4 km \u00b7 '+Math.round(9*(1-v))+' min left';}
function play(){cancelAnimationFrame(raf);if(run){run=false;pl.textContent='Play';return;}let v=+ps.value/100;if(v>=1)v=0;run=true;pl.textContent='Pause';let last=performance.now();(function f(n){v=Math.min(1,v+(n-last)/5000);last=n;set(v);if(v<1&&run)raf=requestAnimationFrame(f);else{run=false;pl.textContent=v>=1?'Replay':'Play';}})(last);}
pl.addEventListener('click',play);ps.addEventListener('input',()=>{run=false;cancelAnimationFrame(raf);pl.textContent='Play';set(ps.value/100);});set(calm?.55:0);if(!calm)setTimeout(play,400);
</script>
</body></html>