GSAP MotionPath Plugin – Animate Elements Along a Path
- Learn how to move elements smoothly along SVG paths using GSAP MotionPath plugin with practical, real-world examples.
Introduction
GSAP MotionPath allows you to animate elements along a custom path, usually an SVG path.
Instead of moving elements only in straight lines (
xandy), MotionPath lets you create curved, natural, and complex animations.It is widely used in:
-
SVG animations
-
Website hero animations
-
Interactive storytelling
-
Product walkthroughs
-
Scroll-based animations
MotionPath is a plugin provided by GreenSock.
-
Basic MotionPath animation:
gsap.to(".box", {
duration: 2,
motionPath: {
path: "#path",
align: "#path"
}
});
Parameters / Options
Option Description Default path SVG path or array of points required align Align element to path none autoRotate Rotates element with path direction false start Start point of path (0–1) 0 end End point of path (0–1) 1
Basic SVG Path Animation
gsap.to(".dot", {
duration: 3,
repeat: -1,
motionPath: {
path: "#curve",
align: "#curve",
autoRotate: true
}
});
Path Animation with ScrollTrigger
gsap.to(".plane", {
scrollTrigger: {
trigger: ".section",
scrub: true
},
motionPath: {
path: "#flightPath",
align: "#flightPath"
}
});
Best Practices
-
Always define SVG
viewBox -
Use
autoRotateonly when needed -
Keep SVG paths simple for performance
-
Test on different screen sizes
-
Combine with
ScrollTriggerfor advanced UX
-