The CSS offset-distance property controls **how far along an offset-path** an element is positioned. It is used together with offset-path to animate elements along curves, lines, circles, or custom SVG-like paths.
Note
β Accepts percentages or lengths
β Used heavily in motion-path animations
β Supported in all modern browsers
π¦ Syntax
offset-distance syntax
offset-distance: <percentage> | <length>;
/* Examples */
offset-distance: 0%; /* start of the path */
offset-distance: 100%; /* end of the path */
offset-distance: 50%; /* halfway */
offset-distance: 40px; /* fixed distance */| Value | Description |
|---|---|
| 0% | Start of the path |
| 100% | End of the path |
| Length (px) | Absolute distance along the path |
π¨ 1. Basic Example
Basic usage
.item {
offset-path: path("M0,0 L200,100");
offset-distance: 40%;
}The element appears 40% along the diagonal path.
π¨ 2. Animate Along a Path
Animation
.ball {
offset-path: path("M0,0 C100,0 150,100 250,80");
animation: move 3s linear infinite;
}
@keyframes move {
to {
offset-distance: 100%;
}
}The ball follows a curved motion path using offset-distance.
π¨ 3. Using Pixels Instead of Percentages
px example
.dot {
offset-path: path("M0,0 L300,0");
offset-distance: 120px;
}The element is placed exactly 120px from the start of the path.
π¨ 4. Bounce Animation Along Path
Bounce motion
.bubble {
offset-path: path("M0,100 C80,0 160,200 240,100");
animation: bounce 2s ease-in-out infinite alternate;
}
@keyframes bounce {
0% { offset-distance: 0%; }
100% { offset-distance: 100%; }
}The element bounces back and forth along the curved path.
π¨ 5. Combine offset-distance + offset-rotate
Follow direction
.car {
offset-path: path("M0,0 L300,60 L350,150");
offset-rotate: auto;
animation: drive 4s ease infinite;
}
@keyframes drive {
to { offset-distance: 100%; }
}The element rotates automatically to face the direction of the path.
π¨ 6. Looping Animation
Loop
.orbit {
offset-path: path("M100,50 A50,50 0 1 1 99,50");
animation: orbit 3s linear infinite;
}
@keyframes orbit {
to { offset-distance: 100%; }
}Perfect for orbit animations or circular loaders.
π Related Motion Path Properties
| Property | Description |
|---|---|
| offset-path | Defines the curve/line/circle to follow |
| offset-rotate | Rotate element along the path |
| offset-anchor | Defines how the element is positioned relative to the path |
π§ͺ Real-World Use Cases
1οΈβ£ Airplane Flight Animation
plane
.plane {
offset-path: path("M0,50 C200,0 300,100 450,40");
offset-rotate: auto;
animation: fly 5s linear infinite;
}
@keyframes fly {
to { offset-distance: 100%; }
}2οΈβ£ Polygon Navigation
polygon path
.nav {
offset-path: path("M0,0 L200,0 L200,200 L0,200 Z");
animation: loop 6s linear infinite;
}
@keyframes loop {
to { offset-distance: 100%; }
}3οΈβ£ Floating Bubble Animation
bubble
.bubble {
offset-path: ray(90deg farthest-side);
animation: float 3s ease-out infinite;
}
@keyframes float {
to { offset-distance: 100%; }
}β οΈ Common Mistakes
- β Using offset-distance without defining offset-path
- β Forgetting to animate offset-distance for motion
- β Expecting rotation without offset-rotate
- β Using invalid SVG path syntax inside path()
Note
π₯ Summary
offset-distance defines where an element is along a motion path. Combined with offset-path and offset-rotate, it creates complex, realistic motion animations that go beyond simple sliding or translating.
- offset-path defines the trajectory
- offset-distance defines progress
- offset-rotate defines orientation