CSS offset-distance Property

The CSS offset-distance property specifies how far an element is positioned along a motion path defined by offset-path.

It accepts percentages and length values, allowing an element to appear at a particular point along a line, curve, circle, or other supported path. The property is commonly animated to create movement along a predefined route without manually calculating horizontal and vertical coordinates.

offset-distance Syntax

The offset-distance property accepts a length or percentage that determines the element's progress along its motion path.

Basic Syntax

selector {
  offset-distance: 50%;
}

Percentage Values

.element {
  offset-distance: 0%;
}
.element {
  offset-distance: 25%;
}
.element {
  offset-distance: 50%;
}
.element {
  offset-distance: 100%;
}

Length Values

.element {
  offset-distance: 100px;
}
.element {
  offset-distance: 5rem;
}

Negative Values

.element {
  offset-distance: -25%;
}
.element {
  offset-distance: -50px;
}

Calculated Values

.element {
  offset-distance: calc(50% + 20px);
}

CSS-Wide Keywords

.element {
  offset-distance: initial;
}
.element {
  offset-distance: inherit;
}
.element {
  offset-distance: unset;
}
.element {
  offset-distance: revert;
}
.element {
  offset-distance: revert-layer;
}

The initial value is 0, which positions the element at the beginning of its motion path.

Property Values

Value Description
<percentage> Specifies progress as a percentage of the total path length.
<length> Specifies the distance traveled along the path using a CSS length.
calc() Combines compatible lengths and percentages to calculate a distance.
initial Resets the property to 0.
inherit Uses the computed value from the parent element.
unset Resets the property to 0 because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value 0
Inherited No
Applies to Transformable elements
Computed value As specified, with lengths made absolute
Animation type By computed value type
Related shorthand offset

How It Works

The offset-distance property determines a point along the motion path established by offset-path.

The browser measures the path from its starting point, determines the requested distance, and positions the element's motion-path anchor at the corresponding location.

Define a Path

.element {
  offset-path: path("M 0 0 L 200 0");
}

This path extends 200 pixels horizontally from its starting point.

Position at the Beginning

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: 0%;
}

The element is positioned at the beginning of the path.

Position Halfway

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: 50%;
}

The element is positioned 100 pixels along the path.

Position at the End

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: 100%;
}

The element is positioned at the end of the path, 200 pixels from its starting point.

Important Consideration

The element's visible placement also depends on offset-anchor and offset-rotate. The distance determines the point on the path, not necessarily the location of the element's top-left corner.

Percentage Values

Percentage values specify how far the element travels relative to the total length of its motion path.

Common Percentage Positions

Value Position
0% Beginning of the path
25% One-quarter of the path length
50% Halfway along the path
75% Three-quarters of the path length
100% End of the path

Quarter Position

.element {
  offset-path: path("M 0 0 L 400 0");
  offset-distance: 25%;
}

The element is positioned 100 pixels along the 400-pixel path.

Three-Quarter Position

.element {
  offset-path: path("M 0 0 L 400 0");
  offset-distance: 75%;
}

The element is positioned 300 pixels along the path.

Percentage Values on Curves

.element {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 50%;
}

The element is positioned halfway along the curve's measured length.

Important Consideration

A percentage represents progress along the actual path length. On a curve, 50% does not necessarily correspond to the horizontal midpoint of the path's bounding box.

Length Values

Length values specify an actual distance traveled along the path.

Pixel Distance

.element {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: 100px;
}

The element is positioned 100 pixels along the path.

Root Font Units

.element {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: 5rem;
}

The distance is calculated using the root element's font size.

Calculated Distance

.element {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: calc(50% + 20px);
}

The element travels halfway along the path plus an additional 20 pixels.

Negative Distance

.element {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: -50px;
}

For an open path, the used distance is clamped to the starting point.

Distance Beyond the Path

.element {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: 400px;
}

For this open path, the used distance is clamped to the endpoint because the specified distance exceeds the path length.

Important Consideration

Length values are useful when the element must travel a fixed distance. Percentages are often more convenient when the path length may change.

Open and Closed Paths

The behavior of offset-distance outside the normal 0% to 100% range depends on whether the path is open or closed.

Open Path

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: 150%;
}

The element remains at the endpoint because the used distance is clamped to the length of the open path.

Negative Distance on an Open Path

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: -25%;
}

The element remains at the beginning of the path.

Closed Path

.element {
  offset-path: path("M 0 0 L 200 0 L 200 200 L 0 200 Z");
  offset-distance: 125%;
}

The closed path wraps the distance around its total length. A distance of 125% places the element at the same path position as 25%.

Negative Distance on a Closed Path

.element {
  offset-path: path("M 0 0 L 200 0 L 200 200 L 0 200 Z");
  offset-distance: -25%;
}

The element is positioned at the same location as 75% along the closed path.

Comparison

Behavior Open Path Closed Path
0% Starting point Starting point
100% Endpoint Returns to the starting point
125% Clamped to endpoint Wraps to 25%
-25% Clamped to starting point Wraps to 75%

Closed paths are useful for continuous loops, while open paths are useful for movement between distinct endpoints.

Path Length and Distance

The meaning of an offset-distance value depends on the total length of the motion path.

Straight-Line Length

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: 50%;
}

The path is 200 pixels long, so 50% corresponds to 100 pixels.

Diagonal Path

.element {
  offset-path: path("M 0 0 L 300 400");
  offset-distance: 50%;
}

The diagonal path is 500 pixels long. The element is positioned 250 pixels along the diagonal, at the coordinate halfway between its endpoints.

Curved Path

.element {
  offset-path: path("M 0 100 C 100 -50 200 250 300 100");
  offset-distance: 50%;
}

The browser calculates the curve's length and positions the element halfway along that measured distance.

Responsive Path Length

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: 75%;
}
@media (max-width: 767px) {
  .element {
    offset-path: path("M 0 0 L 120 0");
  }
}

The element remains at 75% progress, but its actual travel distance changes when the path becomes shorter.

Important Consideration

Percentages provide relative progress, while lengths specify absolute travel distances. Choose the unit according to whether progress or distance should remain consistent.

Using offset-path

The offset-distance property works with offset-path to determine where an element appears along a defined route.

Horizontal Path

.element {
  offset-path: path("M 0 0 L 250 0");
  offset-distance: 50%;
}

The element appears halfway along a horizontal path.

Diagonal Path

.element {
  offset-path: path("M 0 0 L 250 150");
  offset-distance: 50%;
}

The element appears halfway along a diagonal route.

Curved Path

.element {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 50%;
}

The element appears halfway along a quadratic Bézier curve.

Circular Path

.element {
  offset-path: circle(80px);
  offset-distance: 25%;
}

The element is positioned one-quarter of the way around a circular path.

Elliptical Path

.element {
  offset-path: ellipse(120px 60px);
  offset-distance: 75%;
}

The element is positioned three-quarters of the way around an elliptical path.

Important Consideration

Support for CSS basic-shape motion paths may differ from support for SVG path() syntax. Verify compatibility when using newer path types.

Using the offset Shorthand

The offset-distance property is one of five longhand properties represented by the offset shorthand.

Longhand Version

.element {
  offset-path: path("M 0 0 L 200 0");
  offset-distance: 50%;
  offset-rotate: auto;
}

Shorthand Version

.element {
  offset: path("M 0 0 L 200 0") 50% auto;
}

Both declarations establish the same path, distance, and rotation, assuming the other motion-path longhands use their initial values.

Distance and Anchor

.element {
  offset: path("M 0 0 L 200 0") 50% / center;
}

The element is positioned halfway along the path with its center attached to the route.

Distance and Fixed Rotation

.element {
  offset: path("M 0 0 L 200 0") 75% 0deg;
}

The element is positioned 75% along the path without automatic path-following rotation.

Shorthand Reset Behavior

.element {
  offset-distance: 75%;
  offset: path("M 0 0 L 200 0");
}

The shorthand resets offset-distance to 0 because no distance is specified.

Preserving a Custom Distance

.element {
  offset: path("M 0 0 L 200 0");
  offset-distance: 75%;
}

Declaring the longhand after the shorthand preserves the intended distance.

Using offset-rotate

The offset-rotate property controls the orientation of an element as it moves along its path.

Automatic Rotation

.element {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 50%;
  offset-rotate: auto;
}

The element rotates to follow the direction of the curve at its current position.

Fixed Rotation

.element {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 50%;
  offset-rotate: 0deg;
}

The element maintains a fixed orientation instead of following the curve's tangent.

Additional Rotation

.element {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 50%;
  offset-rotate: auto 45deg;
}

The element follows the path direction with an additional 45-degree rotation.

Reverse Orientation

.element {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 50%;
  offset-rotate: reverse;
}

The element follows the path tangent while facing the opposite direction.

Important Consideration

Changing offset-distance can change the element's rotation when offset-rotate: auto is used on a curved path.

Animating offset-distance

Animating offset-distance is a common way to create motion along a predefined path.

Basic Animation

.moving-element {
  offset-path: path("M 0 0 L 250 0");
  offset-distance: 0%;
  animation: move-path 3s linear infinite;
}
@keyframes move-path {
  to {
    offset-distance: 100%;
  }
}

The element travels from the beginning to the end of the path during each animation cycle.

Alternating Direction

.moving-element {
  offset-path: path("M 0 0 L 250 0");
  offset-distance: 0%;
  animation: move-path 3s linear infinite alternate;
}

The element moves forward and then backward along the same route.

Curved Motion

.moving-element {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 0%;
  animation: move-path 4s ease-in-out infinite alternate;
}

The element follows a curve while the easing function controls its rate of progress.

Circular Motion

.orbiting-element {
  offset-path: circle(80px);
  offset-distance: 0%;
  animation: orbit 5s linear infinite;
}
@keyframes orbit {
  to {
    offset-distance: 100%;
  }
}

The element completes one full circuit during each animation cycle.

Animation with Multiple Stops

.moving-element {
  offset-path: path("M 0 0 L 300 0");
  animation: staged-motion 6s linear infinite;
}
@keyframes staged-motion {
  0% {
    offset-distance: 0%;
  }
  30% {
    offset-distance: 25%;
  }
  60% {
    offset-distance: 75%;
  }
  100% {
    offset-distance: 100%;
  }
}

Multiple keyframes control the element's progress at different points in the animation timeline.

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .moving-element,
  .orbiting-element {
    animation: none;
  }
}

This media query disables the animations for users who prefer reduced motion.

Practical Uses

The offset-distance property can position elements at specific points along motion paths or animate them between those points.

Progress Marker

.progress-marker {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: 65%;
  offset-rotate: 0deg;
}

The marker appears 65% along a horizontal route.

Orbiting Icon

.orbit-icon {
  offset-path: circle(100px);
  offset-distance: 25%;
  offset-rotate: 0deg;
}

The icon appears one-quarter of the way around a circular path.

Animated Arrow

.route-arrow {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 0%;
  offset-rotate: auto;
  animation: route-motion 4s linear infinite;
}
@keyframes route-motion {
  to {
    offset-distance: 100%;
  }
}

The arrow follows the curve and rotates to match the path direction.

Interactive Position

.route-marker {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: var(--progress, 0%);
}

A CSS custom property can control the marker's position along the path.

Responsive Motion

.responsive-marker {
  offset-path: path("M 0 0 L 300 0");
  offset-distance: 50%;
}
@media (max-width: 767px) {
  .responsive-marker {
    offset-path: path("M 0 0 L 160 0");
  }
}

The marker remains halfway along the route while the path length changes on smaller screens.

offset-distance Example

This example displays three markers positioned at different percentages along the same curved path. Each marker uses a different offset-distance value.

HTML Example

<div class="distance-demo">
  <svg viewBox="0 0 320 180" aria-hidden="true">
    <path d="M 20 140 Q 160 -100 300 140" fill="none" stroke="#94a3b8" stroke-width="3" stroke-dasharray="6 5"></path>
  </svg>
  <div class="distance-marker marker-start">0%</div>
  <div class="distance-marker marker-middle">50%</div>
  <div class="distance-marker marker-end">100%</div>
</div>

CSS Example

.distance-demo {
  position: relative;
  width: 320px;
  height: 180px;
  max-width: 100%;
}
.distance-demo svg {
  display: block;
  width: 100%;
  height: 100%;
}
.distance-marker {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  offset-path: path("M 20 140 Q 160 -100 300 140");
  offset-anchor: center;
  offset-rotate: 0deg;
}
.marker-start {
  background-color: #2563eb;
  offset-distance: 0%;
}
.marker-middle {
  background-color: #16a34a;
  offset-distance: 50%;
}
.marker-end {
  background-color: #dc2626;
  offset-distance: 100%;
}
Browser Result
0%
50%
100%

The blue marker is at the beginning, the green marker is halfway along the curve, and the red marker is at the endpoint. All three use the same path, anchor, and rotation settings.

Animated Motion Example

The following example animates a single marker along the same curved path.

<div class="animated-distance-demo">
  <svg viewBox="0 0 320 180" aria-hidden="true">
    <path d="M 20 140 Q 160 -100 300 140" fill="none" stroke="#94a3b8" stroke-width="3" stroke-dasharray="6 5"></path>
  </svg>
  <div class="animated-marker"></div>
</div>
.animated-distance-demo {
  position: relative;
  width: 320px;
  height: 180px;
}
.animated-distance-demo svg {
  display: block;
  width: 100%;
  height: 100%;
}
.animated-marker {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: #2563eb;
  offset-path: path("M 20 140 Q 160 -100 300 140");
  offset-distance: 0%;
  offset-anchor: center;
  offset-rotate: 0deg;
  animation: distance-motion 4s linear infinite alternate;
}
@keyframes distance-motion {
  to {
    offset-distance: 100%;
  }
}
@media (prefers-reduced-motion: reduce) {
  .animated-marker {
    animation: none;
  }
}

The marker moves along the curve by animating offset-distance from 0% to 100%. The alternate direction makes it return along the same path.

Common Mistakes

Using offset-distance Without a Motion Path

.element {
  offset-distance: 50%;
}

Without an applicable motion path, changing the distance alone generally does not produce visible movement.

Confusing Distance with Horizontal Position

offset-distance measures progress along a path. It does not simply move an element horizontally by the specified percentage.

Assuming Percentages Use the Container Width

Percentages are based on the path length, not directly on the width or height of the containing element.

Ignoring Path Closure

Distances outside the normal range are clamped on open paths and wrap around closed paths.

Expecting offset-distance to Change Path Geometry

The property changes the position along a path. Use offset-path to change the route itself.

Forgetting Shorthand Reset Behavior

.element {
  offset-distance: 75%;
  offset: circle(80px);
}

The shorthand resets the distance to 0. Declare the distance after the shorthand or include it within the shorthand.

Ignoring the Anchor Point

The position on the path refers to the element's motion-path anchor. Changing offset-anchor can alter the element's visible placement.

Ignoring Automatic Rotation

When offset-rotate: auto is used, an element may rotate as it travels along a curved path.

Using Invalid Units

.element {
  offset-distance: 45deg;
}

Angle values are not valid for offset-distance. Use a length or percentage.

Ignoring Reduced-Motion Preferences

Continuous motion can be distracting. Provide reduced-motion alternatives for nonessential animations.

Important Considerations

Keep the following points in mind when using offset-distance:

  • The property determines progress along a CSS motion path.
  • Its initial value is 0.
  • The property is not inherited.
  • It applies to transformable elements.
  • It is a longhand property of the offset shorthand.
  • It accepts lengths and percentages.
  • Percentage values are relative to the path's total length.
  • Length values specify actual travel distances along the path.
  • Negative distances are permitted.
  • Values beyond the endpoints are clamped on open paths.
  • Distances wrap around closed paths.
  • The property does not define the motion path itself.
  • It is commonly combined with offset-path.
  • offset-anchor determines which point of the element follows the path.
  • offset-rotate determines the element's orientation along the path.
  • Changing the distance can change the element's rotation when automatic rotation is enabled.
  • Animating offset-distance creates movement along a fixed route.
  • CSS easing functions control the rate of progress along the path.
  • Percentage-based progress adapts when the path length changes.
  • Length-based progress maintains a fixed travel distance until endpoint behavior applies.
  • The property does not automatically rearrange surrounding document flow.
  • Motion-path animations should account for reduced-motion preferences.
  • Advanced path types may have different browser compatibility.
  • Test the path, anchor, rotation, and distance together to achieve the intended visual result.

Browser Support

The CSS offset-distance property is Baseline - Widely available. It is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.

Basic motion-path functionality using path() and offset-distance is broadly supported. Support for newer path types and advanced motion-path features may vary.

For current compatibility information, visit Can I Use? and search for offset-distance.

When using advanced path syntax or related motion-path properties, verify compatibility with the browsers required by your project.

Specifications

The offset-distance property is defined in CSS Motion Path Module Level 1.

CSS Motion Path Module Level 1: The offset-distance Property

The specification defines how distances are measured along motion paths, including percentage calculations and the behavior of open and closed paths.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: offset-distance