Tuesday, June 9, 2026

offset-path | CSS-Methods


The offset-path property in CSS defines a motion path for a component to comply with throughout animation.

This property started life as motion-path. This, and all different associated motion-* properties, are being renamed offset-* in the spec. We’re altering the names right here within the almanac. If you wish to use it proper now, in all probability greatest to make use of each syntaxes.

Right here’s an instance utilizing the SVG path syntax:

.thing-that-moves {
  /* "Outdated" syntax. Obtainable in Blink browsers as of ~October 2015 */
  motion-path: path("M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8,0");
 
  /* At the moment spec'd syntax. Ought to be in steady Chrome as of ~December 2016 */
  offset-path: path("M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8,0");
}

This property can’t be animated, fairly it defines the trail for animation. We use the offset-path property to create the animation. Right here’s a easy instance of animating motion-offset with a @keyframes animation:

.thing-that-moves {
  offset-path: path('M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8,0');
  animation: transfer 3s linear infinite;
}

@keyframes transfer {
  100% { 
    motion-offset: 100%;   /* Outdated */
    offset-distance: 100%; /* New */
  }
}

On this demo, the orange circle is being animated alongside the offset-path we set in CSS. We really drew that path in SVG with the very same path() information, however that’s not essential to get the movement.

Say we drew a cool path like this in some SVG enhancing software program:

We’d discover a path like:

The d attribute worth is what we’re after, and we will transfer it straight to CSS and use it because the offset-path:

Word the unitless values within the path syntax. If you happen to’re making use of the CSS to a component inside SVG, these coordinate values will use the coordinate system arrange inside that SVG’s viewBox. If you happen to’re making use of the movement to another HTML component, these values might be pixels.

Additionally notice we used a graphic of a finger pointing to point out how the component is mechanically rotated so it kinda faces ahead. You possibly can management that with offset-rotate:

.mover {
  offset-rotate: auto; /* default, faces ahead */
  offset-rotate: reverse; /* faces backward */
  offset-rotate: 30deg; /* set angle */
  offset-rotate: auto 30deg; /* mix auto habits with a set rotation */
}

Values

As greatest as we will inform, path() and none are the one working values for offset-path.

The offset-path property is meant to just accept all the next values.

  • path(): Specifies a path within the SVG coordinates syntax
  • form(): Creates a path with CSS-y instructions as a substitute of SVG
  • url(): References the ID of an SVG component for use as a motion path
  • none: Specifies no offset path in any respect
  • Form features: A set of CSS features that specify a form in accordance to the CSS Shapes specification, which incorporates:

Right here’s some exams:

Even telling an SVG component to reference a path definied the identical SVG by way of url() doesn’t appear to work.

With the Internet Animations API

Dan Wilson explored a few of this in Future Use: CSS Movement Paths. You've entry to all this identical stuff in JavaScript by the Internet Animations API. For instance, say you’ve outlined a offset-path in CSS, you'll be able to nonetheless management the animation by JavaScript:

Extra Examples

Heads up! Quite a lot of these had been created earlier than the change from motion-* naming to offset-*. Ought to be fairly simple to repair them for those who’re so inclined.

Browser help

Is There One other Method to Do This?

Our personal Sarah Drasner wrote about SMIL, SVG’s native technique for animations, and the way animateMotion is used to animate objects alongside a SVG path. It seems to be like:

GreenSock is one other manner although. Sarah talks about this in GSAP + SVG for Energy Customers: Movement Alongside A Path (SVG not required). Instance:

Related Articles

Latest Articles