- Home
- /
- Tutorials
- /
- CSS Tutorial
- /
- Motion Paths
CSS Animations & Transitions
Motion Paths
Position and animate an element along a path while controlling its rotation and distance. The lesson covers path geometry, offset distance, automatic rotation, anchor points, keyframe animation, basic shapes, and reduced motion.
A motion path lets an element travel along a curve, like a delivery icon moving along a route or a planet orbiting a circle. You draw the path once, then animate how far along it the element is.
Without motion paths, a curved movement needs many keyframes with translate() values and still looks jerky. Here the path does the geometry and the animation only changes one number. It builds on CSS Animations and CSS Transitions.
Path first, then progress
Example
css
.delivery-marker {
offset-path: path("M 20 120 C 100 20 220 20 300 120");
offset-distance: 0%;
offset-rotate: auto;
animation: travel 4s ease-in-out infinite alternate;
}
@keyframes travel {
to { offset-distance: 100%; }
}offset-pathis the route, written as an SVG path. This one is a curve from the left to the right.offset-distanceis how far along the route the element is, from0%to100%. The animation moves it from start to end and back.offset-rotate: autoturns the element to face the direction it is travelling, like a car on a road.
Simple shapes are easier
Example
css
.orbiting {
offset-path: circle(6rem);
offset-rotate: 0deg;
}Instead of writing a path, you can use shapes like circle(). This element orbits a circle with a 6rem radius. offset-rotate: 0deg keeps it upright instead of turning with the curve.
Motion Path Properties
| Property | Purpose | Example |
|---|---|---|
| offset-path | Defines the path an element follows. | offset-path: path("M0,0 C...") |
| offset-distance | Positions the element along the path. | offset-distance: 50% |
| offset-rotate | Controls rotation along the path. | offset-rotate: auto |
| offset-anchor | Sets the element point attached to the path. | offset-anchor: center |
Complete Example
Complete runnable example
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Motion Paths example</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 2rem;
font-family: system-ui, sans-serif;
line-height: 1.5;
}
main { max-width: 70rem; margin-inline: auto; }
article, section, aside, form, .card, .panel {
padding: 1rem;
border: 1px solid #cbd5e1;
border-radius: 0.6rem;
}
.delivery-marker {
offset-path: path("M 20 120 C 100 20 220 20 300 120");
offset-distance: 0%;
offset-rotate: auto;
animation: travel 4s ease-in-out infinite alternate;
}
@keyframes travel {
to { offset-distance: 100%; }
}
.orbiting {
offset-path: circle(6rem);
offset-rotate: 0deg;
}
</style>
</head>
<body>
<main style="position:relative;height:260px"><svg viewBox="0 0 320 160" aria-hidden="true" style="width:320px"><path d="M20 120C100 20 220 20 300 120" fill="none" stroke="#cbd5e1" stroke-width="4"/></svg><span class="delivery-marker" style="position:absolute;left:0;top:0;font-size:2rem">●</span></main>
</body>
</html>Browser Support
Feature | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|
| offset-path | 55 | 79 | 72 | 15.4 |
Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8. A partial-support note is included where it changes how the example behaves.
Respect reduced motion
Moving objects grab attention and can make some people feel sick. For people who ask for reduced motion, do not just make the movement faster; remove the travel. Show the element at its end position, or fade it in. And check that a moving element never covers text or buttons.
Motion Paths exercises
A path
Give the dot the motion path path("M0 0 L200 0").
The HTML your code works on
<style>
.dot { width: 20px; height: 20px; background: red; border-radius: 50%; }
</style>
<div class="dot"></div>Result
