CSS offset-path Property

The CSS offset-path property defines the motion path an element follows when positioned or animated using CSS motion-path properties.

A motion path can be a straight line, curve, circle, ellipse, polygon, or another supported shape. The property defines the route, while offset-distance determines the element's position along it. Related properties control its rotation, anchor point, and starting position.

offset-path Syntax

The offset-path property accepts several types of path definitions, including SVG path data, CSS basic shapes, coordinate boxes, and supported SVG references.

Basic Syntax

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

Keyword Value

.element {
  offset-path: none;
}

SVG Path Data

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

Basic Shapes

.element {
  offset-path: circle(80px);
}
.element {
  offset-path: ellipse(120px 60px);
}
.element {
  offset-path: inset(20px);
}
.element {
  offset-path: polygon(0 0, 100% 0, 50% 100%);
}

Coordinate Box

.element {
  offset-path: border-box;
}
.element {
  offset-path: padding-box;
}
.element {
  offset-path: content-box;
}

Ray Function

.element {
  offset-path: ray(45deg closest-side);
}

SVG Reference

.element {
  offset-path: url("#motion-route");
}

CSS-Wide Keywords

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

The initial value is none, meaning no motion path is established.

Property Values

Value Description
none Specifies that no motion path is used.
path() Defines a path using SVG path commands.
shape() Defines a path using CSS shape commands and coordinates.
circle() Defines a circular motion path.
ellipse() Defines an elliptical motion path.
inset() Defines a rectangular path, optionally with rounded corners.
polygon() Defines a path using a sequence of polygon vertices.
rect() Defines a rectangular path using edge offsets.
xywh() Defines a rectangular path using x, y, width, and height.
ray() Defines a straight motion path extending in a specified direction.
<coord-box> Defines a path around the edges of a selected reference box.
url() References an SVG path element where supported.
initial Resets the property to none.
inherit Uses the computed value from the parent element.
unset Resets the property to none 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 none
Inherited No
Applies to Transformable elements
Computed value As specified, with applicable computed-value conversions
Animation type By computed value type
Related shorthand offset

How It Works

The offset-path property establishes a geometric route that an element can follow.

The browser determines the path's shape and length, calculates a point along it using offset-distance, and positions the element's motion-path anchor at that point. Its orientation can also be adjusted according to the path direction.

Step 1: Define the Path

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

The path begins at coordinate 0 0 and extends 200 pixels horizontally.

Step 2: Select a Position

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

The element is positioned halfway along the route.

Step 3: Control Rotation

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

The element maintains a fixed orientation rather than automatically rotating to follow the path direction.

Step 4: Select an Anchor

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

The center of the element is attached to the calculated path position.

Important Consideration

Defining a motion path does not automatically create an animation. The element can remain at a fixed position along the route until offset-distance changes.

Using path()

The path() function defines a motion path using SVG path commands.

These commands describe points, straight lines, curves, and closed shapes. They provide precise control over the route followed by an element.

Straight Line

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

The M command establishes the starting point, while L draws a straight line to the next coordinate.

Diagonal Line

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

The path extends diagonally from the origin to the specified endpoint.

Quadratic Curve

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

The Q command creates a quadratic Bézier curve using one control point and one endpoint.

Cubic Curve

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

The C command creates a cubic Bézier curve using two control points and one endpoint.

Multiple Segments

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

The element follows a route consisting of several connected line segments.

Closed Path

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

The Z command closes the path by connecting the final point to the starting point.

Common SVG Path Commands

Command Purpose
M Move to a starting point
L Draw a straight line
H Draw a horizontal line
V Draw a vertical line
Q Draw a quadratic Bézier curve
C Draw a cubic Bézier curve
A Draw an elliptical arc
Z Close the current path

Important Consideration

The traditional path() syntax uses SVG path coordinates rather than CSS percentages. For paths that need to respond to a reference box's dimensions, CSS basic shapes or shape() may be more suitable where supported.

Basic Shape Motion Paths

The offset-path property can use CSS basic shapes to define routes without writing SVG path commands.

Circle

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

The element is positioned one-quarter of the way around a circular path with an 80-pixel radius.

Ellipse

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

The element follows an elliptical route with horizontal and vertical radii of 120 and 60 pixels.

Inset Rectangle

.element {
  offset-path: inset(20px);
  offset-distance: 75%;
}

The element follows the outline of an inset rectangle relative to its reference box.

Rounded Rectangle

.element {
  offset-path: inset(20px round 20px);
  offset-distance: 50%;
}

The motion path follows a rectangular outline with rounded corners.

Polygon

.element {
  offset-path: polygon(0 0, 100% 0, 50% 100%);
  offset-distance: 50%;
}

The element follows the perimeter of a triangular polygon.

Rectangle Using xywh()

.element {
  offset-path: xywh(20px 20px 200px 100px);
  offset-distance: 25%;
}

The path follows a rectangle defined by its horizontal position, vertical position, width, and height.

Rectangle Using rect()

.element {
  offset-path: rect(20px 220px 120px 20px);
  offset-distance: 50%;
}

The path follows a rectangle defined by top, right, bottom, and left edge offsets.

Using shape()

.element {
  offset-path: shape(from 0% 50%, line to 100% 50%);
  offset-distance: 50%;
}

The shape() function defines a route using CSS coordinates and shape commands. Unlike traditional SVG path data, it can use percentages relative to its reference box.

Important Consideration

Support for individual basic-shape functions in motion paths varies by browser version. Test newer functions such as shape(), rect(), and xywh() before relying on them in production.

Coordinate Boxes

Coordinate boxes establish the reference area used by supported motion-path shapes. A coordinate box can also be used by itself to create a path around its perimeter.

Border Box

.element {
  offset-path: border-box;
  offset-distance: 25%;
}

The path follows the perimeter of the applicable border box.

Padding Box

.element {
  offset-path: padding-box;
  offset-distance: 50%;
}

The path follows the perimeter of the applicable padding box.

Content Box

.element {
  offset-path: content-box;
  offset-distance: 75%;
}

The path follows the perimeter of the applicable content box.

Margin Box

.element {
  offset-path: margin-box;
  offset-distance: 50%;
}

The path follows the perimeter of the applicable margin box.

Combining a Shape and Coordinate Box

.element {
  offset-path: circle(40%) border-box;
  offset-distance: 25%;
}

The circle is defined relative to the selected reference box.

SVG Coordinate Boxes

SVG elements can also use supported SVG reference boxes, including fill-box, stroke-box, and view-box.

.svg-element {
  offset-path: circle(40%) fill-box;
}

Important Consideration

The reference box depends on the element's containing block and the selected coordinate-box value. It is not always the moving element's own box.

SVG URL Paths

The url() function can reference an SVG <path> element as a motion path in implementations that support SVG URL references.

SVG Path Definition

<svg width="0" height="0" aria-hidden="true">
  <defs>
    <path id="motion-route" d="M 0 100 Q 150 -100 300 100"></path>
  </defs>
</svg>

CSS Reference

.element {
  offset-path: url("#motion-route");
  offset-distance: 50%;
}

The CSS declaration references the SVG path identified by motion-route.

Alternative Using path()

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

The path() function defines the route directly in CSS and generally provides a more portable option for traditional SVG path data.

Important Consideration

SVG URL references have more limited and inconsistent browser support than inline path() definitions. Verify compatibility before using this approach.

Using ray()

The ray() function defines a straight motion path extending from a starting position in a specified direction.

Basic Ray

.element {
  offset-path: ray(45deg closest-side);
  offset-distance: 50%;
}

The element is positioned halfway along a ray directed at 45 degrees, with its length determined by the selected sizing keyword.

Ray Size Keywords

Keyword Description
closest-side Uses the distance from the ray's starting point to the nearest side of the reference box.
farthest-side Uses the distance to the farthest side of the reference box.
closest-corner Uses the distance to the nearest corner of the reference box.
farthest-corner Uses the distance to the farthest corner of the reference box.
sides Uses a distance based on the ray's intersection with the reference box sides.

Horizontal Ray

.element {
  offset-path: ray(90deg farthest-side);
  offset-distance: 75%;
}

In the CSS ray angle system, 90 degrees points to the right.

Vertical Ray

.element {
  offset-path: ray(180deg farthest-side);
  offset-distance: 50%;
}

A 180-degree ray points downward.

Containment

.element {
  offset-path: ray(90deg closest-side contain);
  offset-distance: 100%;
}

The contain keyword adjusts the usable ray length to account for the moving element's dimensions.

Important Consideration

Ray angles use a different directional convention from some CSS gradient angles. A ray at 0deg points upward, 90deg points right, 180deg points down, and 270deg points left.

Using offset-distance

The offset-distance property determines how far an element travels along the route established by offset-path.

Beginning of the Path

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

The element is positioned at the beginning of the path.

Halfway Along the Path

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

The element is positioned halfway along the route.

End of the Path

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

The element is positioned at the endpoint.

Fixed Length

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

The element is positioned 120 pixels along the route.

Important Consideration

For open paths, distances beyond the endpoints are clamped. For closed paths, distances wrap around the route.

Using offset-rotate

The offset-rotate property controls how an element is oriented as it follows its motion 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 align with the direction of the path at its current position.

Fixed Orientation

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

The element maintains its normal orientation rather than 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 Direction

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

The element aligns with the path tangent while facing the opposite direction.

Using offset-anchor

The offset-anchor property specifies which point within the element is attached to the motion path.

Center Anchor

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

The element's center is attached to the calculated path position.

Top-Left Anchor

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

The element's top-left corner is attached to the path.

Custom Anchor

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

A custom point within the element is attached to the route.

Important Consideration

Changing the anchor affects the element's visual placement without changing the path geometry or the selected distance.

Using the offset Shorthand

The offset shorthand combines motion-path properties into a single declaration.

Longhand Version

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

Shorthand Version

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

The shorthand specifies the path, distance, rotation, and anchor. The slash separates the anchor value from the preceding values.

Path and Distance

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

The element is positioned three-quarters of the way along the route.

Path with Fixed Rotation

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

The element remains at a fixed orientation.

Shorthand Reset Behavior

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

The shorthand resets the motion-path longhands, removing the previously defined path.

Important Consideration

Declare longhand overrides after the shorthand when you need to preserve specific values.

Motion Path Animation

Motion-path animation typically uses a fixed offset-path while animating offset-distance from the beginning to the end of the route.

Straight-Line 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 moves horizontally along the route during each animation cycle.

Curved Animation

.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 curved path and reverses direction on alternating cycles.

Circular Animation

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

The element completes a full circuit around the circular route.

Animated Directional Graphic

.moving-arrow {
  offset-path: path("M 0 100 Q 150 -100 300 100");
  offset-distance: 0%;
  offset-rotate: auto;
  animation: move-path 4s linear infinite;
}

The arrow follows the route and rotates according to its direction of travel.

Reduced Motion

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

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

Responsive Motion Paths

Motion paths can be adjusted for different screen sizes, although some path definitions are more responsive than others.

Fixed SVG Path Coordinates

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

The coordinates are fixed, so the path does not automatically scale with the width of its container.

Media Query Adjustment

.element {
  offset-path: path("M 0 0 L 300 0");
}
@media (max-width: 767px) {
  .element {
    offset-path: path("M 0 0 L 150 0");
  }
}

The route becomes shorter on smaller screens.

Percentage-Based Shape

.element {
  offset-path: shape(from 0% 50%, line to 100% 50%);
}

The route can adapt to the dimensions of its reference box when shape() is supported.

Circle Relative to a Reference Box

.element {
  offset-path: circle(40%) border-box;
}

The circle's radius is calculated relative to the reference box.

Important Consideration

Use fixed path coordinates when precise geometry is required. Use responsive shapes or media queries when the route must adapt to different layouts.

offset-path Example

This example shows an element following a curved motion path. The dashed SVG line displays the route, while the blue marker moves along the same coordinates using CSS.

HTML Example

<div class="path-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="path-marker"></div>
</div>

CSS Example

.path-demo {
  position: relative;
  width: 320px;
  height: 180px;
  max-width: 100%;
}
.path-demo svg {
  display: block;
  width: 100%;
  height: 100%;
}
.path-marker {
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 28px;
  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: follow-route 4s linear infinite alternate;
}
@keyframes follow-route {
  to {
    offset-distance: 100%;
  }
}
@media (prefers-reduced-motion: reduce) {
  .path-marker {
    animation: none;
    offset-distance: 50%;
  }
}
Browser Result

The marker follows the dashed curve from left to right and then returns along the same route. The offset-path declaration defines the geometry, while the animation changes offset-distance.

Static Path Position Example

The following example positions an element halfway along a path without animation.

<div class="static-path-demo">
  <div class="static-marker"></div>
</div>
.static-path-demo {
  position: relative;
  width: 320px;
  height: 180px;
}
.static-marker {
  position: absolute;
  top: 0;
  left: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: #16a34a;
  offset-path: path("M 20 140 Q 160 -100 300 140");
  offset-distance: 50%;
  offset-anchor: center;
  offset-rotate: 0deg;
}

The green marker remains at the midpoint of the curved path.

Common Mistakes

Expecting offset-path to Animate Automatically

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

Defining a path does not create an animation. Animate offset-distance to move the element along the route.

Forgetting offset-distance

Without a custom distance, the element remains at the initial position along the path.

Using Invalid SVG Path Data

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

The path() function requires valid SVG path commands, such as M and L.

Assuming path() Percentages Are Supported

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

Traditional SVG path data does not accept CSS percentages in its coordinate commands. Use supported CSS shapes or shape() when percentage-based coordinates are needed.

Confusing offset-path with clip-path

offset-path defines a route for positioning and motion. clip-path controls which parts of an element are visible.

Confusing offset-path with SVG Stroke Rendering

A CSS motion path does not draw a visible line. Use an SVG element or another visual technique to display the route when necessary.

Ignoring Rotation

Automatic rotation can change the element's orientation as it follows a curved route. Use offset-rotate: 0deg when a fixed orientation is required.

Ignoring Anchor Position

The motion path positions the element's anchor point, not necessarily its top-left corner.

Assuming Fixed Paths Are Responsive

Paths defined with fixed SVG coordinates do not automatically resize with their containers.

Using Unsupported Path Types

Not every browser supports all basic shapes, ray options, or SVG URL references equally. Verify compatibility for the syntax you use.

Ignoring Reduced-Motion Preferences

Continuous motion can be distracting. Provide a static or reduced-motion alternative when animation is not essential.

Important Considerations

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

  • The property defines the route used for CSS motion-path positioning.
  • Its initial value is none.
  • The property is not inherited.
  • It applies to transformable elements.
  • It is a longhand property of the offset shorthand.
  • It can define straight lines, curves, circles, ellipses, and other supported shapes.
  • The path() function uses SVG path commands.
  • Traditional SVG path coordinates do not accept CSS percentages.
  • CSS basic shapes can use dimensions relative to a reference box.
  • The shape() function can define paths with CSS coordinates where supported.
  • Coordinate boxes determine the reference area for applicable paths.
  • SVG URL references have more limited compatibility than inline path definitions.
  • The ray() function defines a directional straight-line route.
  • The property does not draw a visible line.
  • Defining a path does not automatically create animation.
  • offset-distance determines progress along the path.
  • offset-rotate controls orientation along the route.
  • offset-anchor selects the point within the element attached to the route.
  • offset-position can influence the starting position for applicable paths.
  • Open paths have distinct endpoints, while closed paths form continuous loops.
  • Path length affects the interpretation of percentage distances.
  • Fixed SVG path coordinates do not automatically adapt to responsive layouts.
  • Motion-path positioning does not automatically rearrange surrounding document flow.
  • Animation timing functions control the rate of progress along a path.
  • Provide reduced-motion alternatives for nonessential animations.
  • Verify compatibility when using newer motion-path functions or coordinate-box features.

Browser Support

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

Support varies for individual path types. The traditional path() syntax is broadly supported, while newer features such as shape(), some basic-shape options, coordinate boxes, and SVG URL references may have different compatibility requirements.

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

When using newer motion-path syntax, verify support for the specific value or function rather than relying only on general support for the property.

Specifications

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

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

The specification defines the supported path values, reference boxes, and how paths are used to calculate motion-path positioning.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: offset-path