CSS offset-distance Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Animation & Motion

What You’ll Learn

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.

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.

📝 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.

🎯 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.

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toElements with a defined offset-path
InheritedNo
AnimatableYes, as a length or percentage
Common useMoving elements from 0% to 100% along a motion path

💎 Property Values

Value typeExampleDescription
Lengthoffset-distance: 100px;A specific distance from the start of the path
Percentageoffset-distance: 50%;A percentage of the total path length
Startoffset-distance: 0%;Places the element at the beginning of the path
Endoffset-distance: 100%;Places the element at the end of the path
0%Path start
25%One quarter
50%Halfway
100%Path end
0 — default start 50% — halfway 100px — fixed length

👀 Live Preview

This dot animates offset-distance from 0% to 100% around a rectangular path:

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;
  }

  @keyframes move {
    from { offset-distance: 0%; }
    to { offset-distance: 100%; }
  }
</style>

<div class="animated"></div>
Try It Yourself

How It Works

The rectangle path defines the route, and the animation changes distance from start to finish around the border.

Example 2 — Stop Halfway with 50%

You can use a fixed percentage to place an element halfway along the path without animation.

halfway-distance.css
.marker {
  offset-path: path("M 20,100 L 280,100");
  offset-distance: 50%;
}
Try It Yourself

How It Works

50% places the marker at the midpoint of the straight path.

📐 Distance Variations

Try fixed lengths and curved paths once you understand percentage-based movement.

Example 3 — Fixed Length Distance

A length value moves the element an exact distance from the start of the path.

length-distance.css
.badge {
  offset-path: path("M 10,70 L 250,70");
  offset-distance: 80px;
}
Try It Yourself

How It Works

Instead of a percentage, the element stops after traveling exactly 80px along the path.

Example 4 — Curved Path Animation

Animate along a curve with alternating motion for a smooth back-and-forth effect.

curve-distance.css
.dot {
  offset-path: path("M 10,80 Q 95,10 180,80 T 350,80");
  animation: follow 4s ease-in-out infinite alternate;
}

@keyframes follow {
  to { offset-distance: 100%; }
}
Try It Yourself

How It Works

The curved path changes direction, but the distance still moves from the start toward 100% of the route.

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;
}

♿ 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.

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 Chrome 46+ · Desktop & Mobile
Full support
Mozilla Firefox 72+ · Desktop & Mobile
Full support
Apple Safari 15.4+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 33+ · Modern versions
Full support

Fallback behavior

When unsupported, the element stays at its normal position instead of following the path.

💻
Internet Explorer No support · Use transform-based animation fallbacks
None
offset-distance property 90% supported

Bottom line: Use offset-distance for modern decorative motion, with reduced-motion and fallback plans in place.

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.

💡 Best Practices

✅ Do

  • Animate from 0% to 100% for full-path motion
  • Define offset-path before setting distance
  • Use linear timing for steady travel around borders
  • Test in Chrome, Firefox, Safari, and Edge
  • Respect reduced-motion preferences

❌ Don’t

  • Expect movement without an offset-path
  • Confuse distance with anchor or rotation properties
  • Overuse looping motion on essential UI
  • Assume every path format behaves identically everywhere
  • Forget a fallback for unsupported browsers

Key Takeaways

Knowledge Unlocked

Five things to remember about offset-distance

Use these points when animating motion paths.

5
Core concepts
02

0 Default

Starts at path start.

Default
📐 03

Percentages

0% to 100% travel.

Values
🛣 04

Needs Path

Uses offset-path.

Companion
🎨 05

Animatable

Great for @keyframes.

Motion

❓ Frequently Asked Questions

offset-distance sets how far an element has traveled along the path defined by offset-path.
The default value is 0, which places the element at the start of the path.
Percentages are most common in animations because 0% is the start and 100% is the end of the path. Lengths are useful when you need an exact distance.
Yes. offset-distance only works when a path already exists through offset-path.
Yes. Animating from 0% to 100% is the standard way to move an element along a motion path.

Practice in the Live Editor

Open the HTML editor, set an offset-path, and animate offset-distance along the route.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful