Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The offset-path property

Reference for the CSS offset-path property: define a path for an element to travel along using path(), shapes, ray() or url(), with a live motion-path example.

The offset-path property gives an element a path to travel along. Once a path is set, the element is no longer placed by its normal position and top/left, but at a point on the path chosen by offset-distance, and turned by offset-rotate. Animating offset-distance makes the element glide along curves that would be painful to describe with translate keyframes.

It is part of CSS Motion Path. The most common value is path(), which takes an SVG path string.

CSS
.rider {
  offset-path: path("M 20 140 C 120 20, 240 260, 340 140");
  offset-distance: 0%;
  animation: ride 4s linear infinite;
}
@keyframes ride {
  to { offset-distance: 100%; }
}

Try it

Riding a curve

The dashed line is only a drawing of the same path. The red box follows it and turns to face the direction of travel because offset-rotate is auto.

Syntax

CSS
offset-path: none | <ray()> | <url> | <basic-shape> | <path()> | [ <basic-shape> || <coord-box> ]

offset-path: path("M 0 0 L 200 100");
offset-path: ray(45deg closest-side);
offset-path: circle(80px at 100px 100px);
offset-path: url(#motion);
  • Initial value: none
  • Applies to: transformable elements
  • Inherited: no
  • Animatable: yes, when both values use the same kind of shape
  • Computed value: as specified, with lengths made absolute

Values

Value Description
none No motion path. The element is placed normally.
path() A string of SVG path commands, with coordinates in pixels.
ray() A straight line from the element's start position in a given direction.
url() Refers to an SVG shape element, such as a <path> in the page. Support is limited.
basic shapes circle(), ellipse(), inset() and polygon() outlines, where supported.
<coord-box> border-box, padding-box and so on, the reference box used to resolve shapes.

Usage notes

  • Coordinates. For path(), coordinates are measured from the top-left of the element's containing block (its reference box). In the example, the stage is position: relative, so path points line up with the SVG drawing.
  • The element's center rides the path. The point of the element that sits on the path is set by offset-anchor, which defaults to the transform origin (the center).
  • Start position. offset-position sets where the element is placed when the path is a ray() or has no starting point.
  • offset shorthand. offset combines position, path, distance, rotation and anchor in one declaration.
  • Combining with transform. A transform is applied after the motion path, so they stack.
  • Static drawing is separate. CSS does not render the path. To show it, draw the same path in SVG, as in the example.
  • Accessibility. Looping motion should respect prefers-reduced-motion and be pausable if it lasts long.
  • Responsive caution. path() uses fixed pixel coordinates and does not scale with the layout. Use scale on a wrapper, or a basic shape with percentages.

Browser support

path() and basic shape motion paths are supported in current versions of the major browsers. Support for url() and ray() varies, so check a compatibility table before using them.