CSS Motion Path for SVG Animation
CSS Motion Path lets an element travel along a defined shape instead of moving in a straight line. For SVG teams, that matters: the same visual paths designers draw for icons, maps, dashboards, and product illustrations can become animation routes in the browser.
This guide explains how offset-path, offset-distance, and SVG path data fit together, then shows a production workflow for cleaner, more accessible motion.
TL;DR
- Use
offset-pathto define the route andoffset-distanceto move along it. - SVG path data can be reused as a CSS
path()value. - Keep animated paths simple, responsive, and easy to preview.
- Always support
prefers-reduced-motion. - Validate and optimize SVG assets before shipping motion-heavy UI.
What is CSS Motion Path?
CSS Motion Path is a set of CSS properties that place an element on a path and move it along that path. The two properties you will use most are:
offset-path: the path or shape the element follows.offset-distance: the element's progress along that path.
You can animate offset-distance from 0% to 100% with keyframes:
.marker {
offset-path: path("M20 120 C120 20 220 220 340 80");
animation: travel 4s linear infinite;
}
@keyframes travel {
to {
offset-distance: 100%;
}
}
The path value above uses SVG path syntax. That makes Motion Path especially useful when your design already contains an SVG route.
Why SVG paths are a natural fit
SVG paths describe curves, arcs, and complex shapes with compact data. CSS Motion Path can use that same path data for layout animation, so you do not need to approximate a curve with many translate() keyframes.
Good use cases include:
- Product tours that guide attention through a UI.
- Animated map pins, delivery routes, or onboarding trails.
- Icons that move along circular or curved paths.
- Data visualizations where a marker follows a chart line.
For asset work, extract the route first with SVG Path Extractor, preview the original in SVG Viewer, then simplify the source with SVG Optimizer.
Basic example
Use a visible SVG path for the guide line and move a separate HTML element along the same route.
<svg viewBox="0 0 360 160" aria-hidden="true">
<path d="M20 120 C120 20 220 220 340 80" fill="none" stroke="currentColor" />
</svg>
<span class="dot" aria-label="Upload progress"></span>
.dot {
width: 16px;
height: 16px;
border-radius: 999px;
background: #14b8a6;
offset-path: path("M20 120 C120 20 220 220 340 80");
offset-distance: 0%;
offset-rotate: auto;
animation: move-dot 3200ms ease-in-out infinite;
}
@keyframes move-dot {
to {
offset-distance: 100%;
}
}
offset-rotate: auto rotates the element to match the path direction. Use it for arrows or vehicles. Skip it for dots, badges, and labels if rotation makes them harder to read.
Responsive motion paths
The tricky part is that CSS path() values are not automatically scaled like an SVG viewBox. If your layout changes size, a fixed path may drift away from the visual artwork.
Best practices:
- Keep the motion area in a predictable container.
- Use an SVG
viewBoxfor the visible artwork. - Match the CSS path coordinate system to the same design size.
- Test at mobile, tablet, and desktop widths.
When the route needs to scale with the SVG itself, consider animating an SVG element inside the SVG or using CSS variables to swap simpler path values at breakpoints.
Accessibility and UX
Motion should guide attention, not fight the reader. For production UI:
- Respect
prefers-reduced-motion. - Avoid infinite animation on important reading pages unless it is subtle.
- Pause motion on hover only when that helps inspection.
- Do not rely on motion alone to explain state.
- Keep CTA text, labels, and controls stable while animation runs.
@media (prefers-reduced-motion: reduce) {
.dot {
animation: none;
offset-distance: 100%;
}
}
This gives motion-sensitive users a calm final state instead of a moving target.
SVGView workflow for motion paths
Use this workflow before putting CSS Motion Path into production:
- Open the source artwork in SVG Viewer and confirm the viewBox.
- Extract candidate routes with SVG Path Extractor.
- Clean untrusted or copied markup with SVG Sanitizer.
- Format the SVG with SVG Formatter so the path is reviewable.
- Run SVG Optimizer, then test the animated path again.
Common mistakes
- Using a huge exported path: complex paths can make animation harder to tune. Simplify where possible.
- Forgetting reduced motion: this is a UX issue, not a nice-to-have.
- Animating layout properties: use Motion Path progress instead of many top/left changes.
- Letting the marker cover content: motion should not block copy, controls, or form fields.
- Skipping browser checks: test the actual browsers your audience uses.
Final takeaway
CSS Motion Path is a clean way to turn SVG path data into polished interface motion. Start with a simple path, keep the animation purposeful, and build a workflow around previewing, extracting, sanitizing, and optimizing the SVG before you ship.
Next steps
- Extract a route with SVG Path Extractor.
- Preview the source in SVG Viewer.
- Clean and optimize with SVG Sanitizer and SVG Optimizer.