Motion Path Follow
An element travelling along a curved path with easing, auto-rotation and speed controls.
AI prompt
Clean illustration of a small paper plane flying along a dashed curved loop path across an off-white sky, the plane rotated to follow the path direction at three positions with faint ghost copies behind it, dots marking evenly spaced time steps closer together at the start and wider in the middle to show easing, start and end markers, thin blue dashed path, flat vector style. Negative: gradients, clutter, text errors. Reduced motion: static illustration.About this pattern
Definition
Moving an element along a curve instead of a straight line feels natural, like a leaf, a car or a paper plane. In CSS this is offset-path; in SVG you can read points from the path with getPointAtLength. Easing changes how progress along the path maps to time, and rotation can follow the path direction.
Purpose & UX principles
- Compute progress t from 0 to 1, apply an easing function, then read the point at t times the path length.
- For rotation, sample a point slightly ahead and use atan2 for the angle.
- Keep path and element in the same coordinate space.
- offset-path with offset-distance does this in CSS where supported.
Interaction states
- Easing buttons, a Rotate with path switch and Play.
Motion specification
- One trip takes 3 seconds.
- Reduced motion: no autoplay; the Position slider moves it.
Responsive behaviour
- Respect reduced motion by showing a static trail or letting people scrub.
- Do not loop endlessly beside text people are trying to read.
Code
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Easing"><button data-p="0" aria-pressed="true">Linear</button><button data-p="1" aria-pressed="false">Ease in-out</button><button data-p="2" aria-pressed="false">Overshoot</button></div><svg class="mp" viewBox="0 0 300 120" role="img" aria-label="A paper plane following a curved path"><path id="pa" d="M20 90 C60 10 110 10 140 60 S210 110 240 50 S280 20 284 30" fill="none" stroke="#9db8ff" stroke-width="2" stroke-dasharray="4 5"/><circle cx="20" cy="90" r="4" fill="#1f9d55"/><circle cx="284" cy="30" r="4" fill="#d94f3d"/><g id="pl"><path d="M-9 -6 L11 0 L-9 6 L-5 0Z" fill="#171717"/></g></svg><label class="rw">Position <b id="pv">0%</b><input id="ps" type="range" min="0" max="100" value="0"></label><div class="two"><label class="sw"><input id="ro" type="checkbox" checked> Rotate with path</label><button class="mini" id="go" type="button">Play</button></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:1px solid var(--line);border-radius:12px;background:#fbfbf9;display:block}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.sw{display:flex;gap:6px;align-items:center;font-size:12px;color:var(--muted)}.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}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const pa=document.getElementById('pa'),pl=document.getElementById('pl'),ps=document.getElementById('ps'),ro=document.getElementById('ro'),go=document.getElementById('go'),bs=[...document.querySelectorAll('#pre button')],calm=matchMedia('(prefers-reduced-motion:reduce)').matches,L=pa.getTotalLength();let p=1,raf=0,run=false;
const E=[t=>t,t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,t=>{const c1=1.70158,c3=c1+1;return 1+c3*Math.pow(t-1,3)+c1*Math.pow(t-1,2);}];
function place(t){const e=Math.max(0,Math.min(1,E[p](t))),d=Math.max(0,Math.min(L,e*L)),a=pa.getPointAtLength(d),b=pa.getPointAtLength(Math.min(L,d+1.5)),ang=ro.checked?Math.atan2(b.y-a.y,b.x-a.x)*180/Math.PI:0;pl.setAttribute('transform','translate('+a.x+' '+a.y+') rotate('+ang+')');ps.value=Math.round(t*100);document.getElementById('pv').textContent=Math.round(t*100)+'%';}
function play(){if(run){run=false;cancelAnimationFrame(raf);go.textContent='Play';return;}let t=+ps.value/100;if(t>=1)t=0;const t0=performance.now(),v0=t;run=true;go.textContent='Pause';(function f(n){const k=Math.min(1,v0+(n-t0)/3000);place(k);if(k<1&&run)raf=requestAnimationFrame(f);else{run=false;go.textContent=k>=1?'Replay':'Play';}})(t0);}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;bs.forEach(x=>x.setAttribute('aria-pressed',String(x===b)));place(+ps.value/100);}));bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));ps.addEventListener('input',()=>{run=false;cancelAnimationFrame(raf);go.textContent='Play';place(ps.value/100);});ro.addEventListener('change',()=>place(+ps.value/100));go.addEventListener('click',play);place(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>Motion Path Follow — 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:1px solid var(--line);border-radius:12px;background:#fbfbf9;display:block}.two{display:grid;grid-template-columns:1fr 1fr;gap:12px}.sw{display:flex;gap:6px;align-items:center;font-size:12px;color:var(--muted)}.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}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="pre" id="pre" role="group" aria-label="Easing"><button data-p="0" aria-pressed="true">Linear</button><button data-p="1" aria-pressed="false">Ease in-out</button><button data-p="2" aria-pressed="false">Overshoot</button></div><svg class="mp" viewBox="0 0 300 120" role="img" aria-label="A paper plane following a curved path"><path id="pa" d="M20 90 C60 10 110 10 140 60 S210 110 240 50 S280 20 284 30" fill="none" stroke="#9db8ff" stroke-width="2" stroke-dasharray="4 5"/><circle cx="20" cy="90" r="4" fill="#1f9d55"/><circle cx="284" cy="30" r="4" fill="#d94f3d"/><g id="pl"><path d="M-9 -6 L11 0 L-9 6 L-5 0Z" fill="#171717"/></g></svg><label class="rw">Position <b id="pv">0%</b><input id="ps" type="range" min="0" max="100" value="0"></label><div class="two"><label class="sw"><input id="ro" type="checkbox" checked> Rotate with path</label><button class="mini" id="go" type="button">Play</button></div></div>
</div>
<script>
const pa=document.getElementById('pa'),pl=document.getElementById('pl'),ps=document.getElementById('ps'),ro=document.getElementById('ro'),go=document.getElementById('go'),bs=[...document.querySelectorAll('#pre button')],calm=matchMedia('(prefers-reduced-motion:reduce)').matches,L=pa.getTotalLength();let p=1,raf=0,run=false;
const E=[t=>t,t=>t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2,t=>{const c1=1.70158,c3=c1+1;return 1+c3*Math.pow(t-1,3)+c1*Math.pow(t-1,2);}];
function place(t){const e=Math.max(0,Math.min(1,E[p](t))),d=Math.max(0,Math.min(L,e*L)),a=pa.getPointAtLength(d),b=pa.getPointAtLength(Math.min(L,d+1.5)),ang=ro.checked?Math.atan2(b.y-a.y,b.x-a.x)*180/Math.PI:0;pl.setAttribute('transform','translate('+a.x+' '+a.y+') rotate('+ang+')');ps.value=Math.round(t*100);document.getElementById('pv').textContent=Math.round(t*100)+'%';}
function play(){if(run){run=false;cancelAnimationFrame(raf);go.textContent='Play';return;}let t=+ps.value/100;if(t>=1)t=0;const t0=performance.now(),v0=t;run=true;go.textContent='Pause';(function f(n){const k=Math.min(1,v0+(n-t0)/3000);place(k);if(k<1&&run)raf=requestAnimationFrame(f);else{run=false;go.textContent=k>=1?'Replay':'Play';}})(t0);}
bs.forEach(b=>b.addEventListener('click',()=>{p=+b.dataset.p;bs.forEach(x=>x.setAttribute('aria-pressed',String(x===b)));place(+ps.value/100);}));bs.forEach(b=>b.setAttribute('aria-pressed',String(+b.dataset.p===p)));ps.addEventListener('input',()=>{run=false;cancelAnimationFrame(raf);go.textContent='Play';place(ps.value/100);});ro.addEventListener('change',()=>place(+ps.value/100));go.addEventListener('click',play);place(0);if(!calm)setTimeout(play,400);
</script>
</body></html>