CSS Portal

path() CSS Function

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
path()
CSS FunctionThis function is supported in some modern browsers, but not all.
Updated 31st December 2025

Description

The path() CSS function allows you to define a custom motion path for elements to follow, typically used with the offset-path property. Instead of relying on standard geometric shapes like circles or polygons, path() lets you specify a vector path directly using a series of commands similar to those in SVG path data. This provides precise control over the trajectory of an element during animations or transitions.

Each path is defined using a combination of commands such as M for “move to”, L for “line to”, C for “cubic Bézier curve”, Q for “quadratic Bézier curve”, and Z for closing the path. These commands allow complex motion patterns that can loop, curve, or zigzag, offering more creative possibilities than simpler path functions like circle() or ellipse().

A practical example of using path() is animating a div along a custom trajectory:

.my-element {
  offset-path: path('M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80');
  offset-rotate: auto;
  animation: moveAlongPath 5s infinite;
}

@keyframes moveAlongPath {
  0% { offset-distance: 0%; }
  100% { offset-distance: 100%; }
}

In this example, the offset-rotate property ensures the element rotates along the curve naturally. Using path() is particularly useful for complex animations like moving objects along intricate tracks, following curves in a graph, or animating decorative elements in a web page.

The function also supports relative and absolute coordinates, giving flexibility in scaling paths according to the element’s container. While path() can be combined with properties like offset-distance, it cannot be directly used for layout; it is strictly for animation and motion paths.

Syntax

path([<'fill-rule'>,]?<string>)

Values

  • <'fill-rule'>The filling rule for the interior of the path. Possible values are nonzero or evenodd. The default value is nonzero.
  • <string>The string is a data string for defining an SVG path.

Example

<div class="container">
<div class="traveler"></div>
</div>
/* The area where the animation happens */
.container {
width: 100%;
height: 400px;
border: 2px dashed #ccc;
position: relative;
background-color: #f9f9f9;
}

/* The element that will move */
.traveler {
width: 30px;
height: 30px;
background-color: #ff4757;
border-radius: 50%;

/* Define the motion path using the path() function */
/* M = Move to, C = Cubic Bezier Curve */
offset-path: path("M 50 200 C 150 50, 350 350, 450 200");

/* Animate the movement along the path */
animation: moveAlongPath 4s infinite alternate ease-in-out;
}

@keyframes moveAlongPath {
from {
offset-distance: 0%;
}
to {
offset-distance: 100%;
}
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS path() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee