The offset-distance property controls how far an element has moved along a motion path. It is the property you animate when you want something to travel from the start to the end of a route.
01
Path Progress
Distance along route.
02
Syntax
Length or percentage.
03
0 Default
Starts at path start.
04
Percentages
0% to 100% travel.
05
With offset-path
Needs a defined path.
06
@keyframes
Animate movement.
Fundamentals
Introduction
The offset-distance property in CSS is used to define the distance of an element along an offset path.
This property is typically used with offset-path to animate elements along a predefined path, such as a line, curve, or any other shape. By specifying the offset-distance, you can control the position of the element along the path, making it useful for creating dynamic and engaging animations.
Definition and Usage
Think of offset-path as the road and offset-distance as how far the car has driven. A value of 0% keeps the element at the beginning, while 100% places it at the end.
In most tutorials and demos, beginners animate this property because it creates smooth motion without manually calculating coordinates.
💡
Beginner Tip
Start with offset-distance: 0% to 100% in @keyframes before trying fixed length values.
Foundation
📝 Syntax
The syntax for the offset-distance property is simple and allows you to specify the distance as a length or percentage value:
syntax.css
element{offset-distance:value;}
The value can be a length such as 10px or 2em, or a percentage such as 50%.
Basic Example
offset-distance.css
.dot{offset-path:path("M10 10 H 290 V 290 H 10 Z");offset-distance:50%;}
Syntax Rules
Define the path first with offset-path.
Use percentages for start-to-end motion along the full path.
Use lengths when you need an exact distance from the path start.
Animate the property with @keyframes for continuous movement.
Defaults
🎯 Default Value
The default value of the offset-distance property is 0, which means the element starts at the beginning of the offset path.
That is why elements with a path but no distance value appear parked at the route’s starting point.
Cheat Sheet
⚡ Quick Reference
Question
Answer
Initial value
0
Applies to
Elements with a defined offset-path
Inherited
No
Animatable
Yes, as a length or percentage
Common use
Moving elements from 0% to 100% along a motion path
This dot animates offset-distance from 0% to 100% around a rectangular path:
Hands-On
Examples Gallery
Use offset-distance to move elements along lines, rectangles, and curves.
📏 Distance Basics
Percentages are the easiest way to move an element from the start to the end of a path.
Example 1 — Circle Animating a Rectangle Path
In this example, a circle moves along a rectangular path by animating offset-distance from 0% to 100%.
rectangle-distance.html
<style>.animated{width:20px;height:20px;background-color:red;border-radius:50%;offset-path:path("M10 10 H 290 V 290 H 10 Z");animation:move 5s infinite linear;}@keyframesmove{from{offset-distance:0%;}to{offset-distance:100%;}}</style><divclass="animated"></div>
The curved path changes direction, but the distance still moves from the start toward 100% of the route.
Companion
Pair with offset-path and offset-anchor
offset-distance only controls progress along a path. You still need offset-path to define the route, and you may use offset-anchor when the element should sit on the path from a specific point.
motion-path-set.css
.dot{offset-path:circle(70px at 120px 80px);offset-distance:0%;offset-anchor:center;animation:orbit 4s linear infinite;}
A11y
♿ Accessibility
Respect reduced motion — Disable path animations when prefers-reduced-motion: reduce is set.
Keep motion decorative — Do not rely on movement alone to communicate important state.
Avoid endless distracting loops — Subtle motion is easier to read around.
Provide static fallbacks — Ensure content remains usable if motion path features are unsupported.
🧠 How offset-distance Works
1
A path is created
offset-path defines the full route the element can follow.
offset-path
2
Distance sets progress
offset-distance chooses how far along that route the element currently is.
Progress
3
Animation updates the value
Changing distance over time in @keyframes creates visible motion along the path.
Animation
=
📏
Smooth path motion
The element travels along the route without manually setting x/y coordinates.
Compatibility
Browser Compatibility
The offset-distance property is supported in most modern browsers, including Chrome, Edge, Firefox, Safari, and Opera. Test your animations across browsers to ensure compatibility.
✓ Baseline · Modern browsers
Strong support for path animation
Current browser versions handle percentage-based motion along paths reliably in most demos.
90%Modern browser support
Google Chrome46+ · Desktop & Mobile
Full support
Mozilla Firefox72+ · Desktop & Mobile
Full support
Apple Safari15.4+ · macOS & iOS
Full support
Microsoft Edge79+ · Chromium
Full support
Opera33+ · Modern versions
Full support
Fallback behavior
When unsupported, the element stays at its normal position instead of following the path.
💻
Internet ExplorerNo support · Use transform-based animation fallbacks
None
offset-distance property90% supported
Bottom line: Use offset-distance for modern decorative motion, with reduced-motion and fallback plans in place.
Wrap Up
Conclusion
The offset-distance property is a versatile tool for creating animations along a predefined path in CSS.
By adjusting the distance along the path, you can control the position and movement of elements, making it ideal for interactive and visually appealing web design. Experiment with different paths and distances to explore the full potential of this property.