CSS offset Property
The CSS offset property is a shorthand that controls an element's position and orientation along a motion path.
It combines five motion-path properties into one declaration, allowing elements to follow straight lines, curves, circles, and other paths. The shorthand is useful for animations, interactive graphics, progress indicators, and decorative movement without manually calculating individual positions.
offset Syntax
The offset shorthand accepts a motion path, an optional distance and rotation, and optional position and anchor values.
Basic Syntax
selector {
offset: path("M 0 0 L 200 0") 50% auto;
}
This declaration places the element halfway along a horizontal path and automatically aligns its orientation with the path.
Path Only
.element {
offset: path("M 0 0 L 200 0");
}
Path and Distance
.element {
offset: path("M 0 0 L 200 0") 75%;
}
Path, Distance, and Rotation
.element {
offset: path("M 0 0 L 200 0") 50% auto 30deg;
}
Circular Motion Path
.element {
offset: circle(80px) 25% auto;
}
Custom Anchor
.element {
offset: path("M 0 0 L 200 0") 50% / 50% 50%;
}
The slash separates the offset-anchor value from the preceding motion-path values.
Explicit Starting Position
.element {
offset: 100px 100px path("M 0 0 L 200 0") 50%;
}
The initial position specifies the reference point used to establish the motion path's placement.
CSS-Wide Keywords
.element {
offset: initial;
}
.element {
offset: inherit;
}
.element {
offset: unset;
}
.element {
offset: revert;
}
.element {
offset: revert-layer;
}
As a shorthand, offset resets its omitted longhand properties to their initial values. Use individual longhand properties when only one part of an existing motion-path configuration needs to change.
Property Values
The offset shorthand combines values from five related CSS properties.
| Component | Description |
|---|---|
offset-path |
Defines the path or reference geometry used to position the element. |
offset-distance |
Specifies how far the element travels along its path. |
offset-rotate |
Controls the element's rotation relative to the path direction. |
offset-anchor |
Specifies the point within the element that is placed on the path. |
offset-position |
Specifies the starting reference position for the motion path. |
initial |
Resets all five longhand properties to their initial values. |
inherit |
Inherits the computed values of all five longhand properties from the parent. |
unset |
Resets the non-inherited longhand properties to their initial values. |
revert |
Reverts the longhand properties according to cascade origin rules. |
revert-layer |
Reverts the longhand properties according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | The initial values of its longhand properties |
| Inherited | No |
| Applies to | Transformable elements |
| Computed value | Determined by the individual longhand properties |
| Animation type | Determined by the individual longhand properties |
| Property type | Shorthand |
How It Works
CSS motion paths allow an element to move along a defined route without changing its normal layout position.
The browser determines the path geometry, calculates the requested distance along that path, places the element's anchor point at the resulting position, and applies the specified rotation.
Define a Motion Path
.moving-element {
offset-path: path("M 0 0 L 200 0");
}
The path begins at its starting point and extends 200 pixels horizontally.
Choose a Position Along the Path
.moving-element {
offset-path: path("M 0 0 L 200 0");
offset-distance: 50%;
}
The element is positioned halfway along the path.
Combine the Properties
.moving-element {
offset: path("M 0 0 L 200 0") 50%;
}
The shorthand provides the same path and distance values while resetting the other motion-path longhands to their initial values.
Animate the Distance
.moving-element {
offset: path("M 0 0 L 200 0") 0%;
animation: move-along-path 3s linear infinite;
}
@keyframes move-along-path {
to {
offset-distance: 100%;
}
}
The element travels from the beginning to the end of the path during each animation cycle.
Important Consideration
Motion-path positioning affects visual rendering. It does not automatically rearrange surrounding elements or change the space reserved for the element in normal document flow.
Shorthand Properties
The offset property combines five longhand properties into a single declaration.
Longhand Version
.element {
offset-position: auto;
offset-path: path("M 0 0 L 200 0");
offset-distance: 50%;
offset-rotate: auto;
offset-anchor: auto;
}
Shorthand Version
.element {
offset: path("M 0 0 L 200 0") 50%;
}
Both declarations establish the same motion-path configuration.
Initial Longhand Values
| Property | Initial Value |
|---|---|
offset-position |
normal |
offset-path |
none |
offset-distance |
0 |
offset-rotate |
auto |
offset-anchor |
auto |
Shorthand Reset Behavior
.element {
offset-anchor: left top;
offset: circle(80px) 50%;
}
The second declaration resets offset-anchor to auto because the shorthand does not specify an anchor.
Preserving an Existing Anchor
.element {
offset: circle(80px) 50%;
offset-anchor: left top;
}
Declaring the anchor after the shorthand allows the custom anchor to override the shorthand's reset.
offset-path
The offset-path property defines the geometry that an element follows.
Straight Path
.element {
offset-path: path("M 0 0 L 200 0");
}
The SVG path data defines a straight horizontal line.
Curved Path
.element {
offset-path: path("M 0 100 Q 150 -100 300 100");
}
The quadratic Bézier curve creates an arched motion path.
Circular Path
.element {
offset-path: circle(80px);
}
The element follows a circular path with an 80-pixel radius.
Shorthand Equivalent
.element {
offset: circle(80px);
}
The shorthand sets the circular path and resets the remaining motion-path properties.
Important Consideration
The path() function uses SVG path-data syntax. CSS basic shapes such as circle() and ellipse() provide alternative ways to define motion paths.
offset-distance
The offset-distance property specifies how far an element travels along its motion path.
Starting Position
.element {
offset: path("M 0 0 L 200 0") 0%;
}
The element is positioned at the beginning of the path.
Halfway Position
.element {
offset: path("M 0 0 L 200 0") 50%;
}
The element is positioned halfway along the path.
End Position
.element {
offset: path("M 0 0 L 200 0") 100%;
}
The element is positioned at the end of the path.
Length-Based Distance
.element {
offset: path("M 0 0 L 200 0") 75px;
}
The element is positioned 75 pixels along the path.
Closed and Open Paths
On a closed path, distances can wrap around the path. On an open path, distances beyond the endpoints are clamped to the available path length.
Important Consideration
Percentage distances are measured relative to the path's total length, not the width or height of the containing element.
offset-rotate
The offset-rotate property controls how an element is oriented while following its motion path.
Automatic Rotation
.element {
offset: path("M 0 0 L 200 100") 50% auto;
}
The element automatically rotates to follow the direction of the path.
Fixed Rotation
.element {
offset: path("M 0 0 L 200 100") 50% 0deg;
}
The element uses a fixed rotation instead of automatically following the path direction.
Additional Rotation
.element {
offset: path("M 0 0 L 200 100") 50% auto 45deg;
}
The element follows the path direction with an additional 45-degree rotation.
Reverse Direction
.element {
offset: path("M 0 0 L 200 100") 50% reverse;
}
The element follows the path's tangent while facing the opposite direction.
Important Consideration
Automatic rotation is useful for directional objects, such as arrows or vehicles. Fixed rotation is useful when the element should maintain a consistent orientation.
offset-anchor
The offset-anchor property specifies which point within the element is placed on the motion path.
Center Anchor
.element {
offset: circle(80px) 25% / center;
}
The center of the element is placed on the path.
Top-Left Anchor
.element {
offset: circle(80px) 25% / left top;
}
The element's top-left anchor point is placed on the path.
Percentage Anchor
.element {
offset: circle(80px) 25% / 75% 50%;
}
The anchor is positioned 75% across and 50% down the element's reference box.
Longhand Equivalent
.element {
offset-path: circle(80px);
offset-distance: 25%;
offset-anchor: center;
}
Important Consideration
The anchor affects which point follows the path. Changing the anchor can visibly shift the element even when the path and distance remain unchanged.
offset-position
The offset-position property establishes the starting reference position used when placing a motion path.
Explicit Starting Position
.element {
offset-position: 100px 100px;
offset-path: path("M 0 0 L 200 0");
offset-distance: 50%;
}
The motion path is established using the specified reference position.
Shorthand Equivalent
.element {
offset: 100px 100px path("M 0 0 L 200 0") 50%;
}
Centered Starting Position
.element {
offset-position: center;
offset-path: circle(80px);
}
The reference position is centered within the applicable containing block.
Default Position
.element {
offset-position: normal;
}
The normal value uses the default motion-path positioning behavior.
Important Consideration
The effect of offset-position depends on the path type and its coordinate system. For paths with explicit coordinates, the placement behavior differs from paths defined using basic shapes.
Motion Path Shapes
Motion paths can use several types of geometry, including straight lines, curves, and CSS basic shapes.
Straight Line
.element {
offset: path("M 0 0 L 250 0") 50%;
}
The element is positioned halfway along a horizontal line.
Diagonal Line
.element {
offset: path("M 0 0 L 250 150") 50%;
}
The element follows a diagonal path.
Quadratic Curve
.element {
offset: path("M 0 100 Q 150 -100 300 100") 50%;
}
The element follows a curved path controlled by a quadratic Bézier command.
Cubic Curve
.element {
offset: path("M 0 100 C 100 -50 200 250 300 100") 50%;
}
The element follows a cubic Bézier curve with two control points.
Circle
.element {
offset: circle(80px) 50%;
}
The element is positioned halfway around a circular path.
Ellipse
.element {
offset: ellipse(120px 60px) 50%;
}
The element follows an elliptical path with different horizontal and vertical radii.
Polygon
.element {
offset: polygon(0 0, 100% 0, 100% 100%, 0 100%) 50%;
}
The element follows a closed path defined by the polygon's edges.
Important Consideration
Browser support may differ between SVG path() motion paths and newer CSS basic-shape motion paths. Check compatibility before relying on advanced shape syntax.
Animating Motion Paths
The offset property is particularly useful with CSS animations. A common technique is to define a path and animate offset-distance.
Basic Motion Animation
.moving-element {
offset: path("M 0 0 L 250 0") 0%;
animation: move-path 3s linear infinite alternate;
}
@keyframes move-path {
to {
offset-distance: 100%;
}
}
The element moves from one end of the path to the other and then reverses direction.
Circular Animation
.orbiting-element {
offset: circle(80px) 0% auto;
animation: orbit 4s linear infinite;
}
@keyframes orbit {
to {
offset-distance: 100%;
}
}
The element travels around a circular path repeatedly.
Curved Animation
.curved-element {
offset: path("M 0 100 Q 150 -100 300 100") 0% auto;
animation: curved-motion 4s ease-in-out infinite alternate;
}
@keyframes curved-motion {
to {
offset-distance: 100%;
}
}
The element follows a curved route with easing applied to its progress along the path.
Reduced Motion
@media (prefers-reduced-motion: reduce) {
.moving-element,
.orbiting-element,
.curved-element {
animation: none;
}
}
This media query disables the animations for users who request reduced motion.
Important Consideration
Animating offset-distance is often simpler than repeatedly changing the entire shorthand. Keep the path fixed when only the element's progress needs to change.
offset vs. transform
The offset and transform properties both affect an element's visual position, but they use different approaches.
Using transform
.element {
transform: translateX(200px);
}
The element is translated 200 pixels horizontally.
Using offset
.element {
offset: path("M 0 0 L 200 0") 100%;
}
The element is positioned at the end of a defined horizontal motion path.
Comparison
| Feature | offset | transform |
|---|---|---|
| Primary purpose | Positioning and orienting an element along a path | Translating, rotating, scaling, and skewing an element |
| Curved movement | Uses a defined motion path | Requires coordinated transformations or keyframes |
| Automatic path rotation | Supported through offset-rotate |
Requires an explicit rotation strategy |
| Normal document flow | Does not rearrange surrounding layout | Does not rearrange surrounding layout |
| Can be combined | Yes | Yes |
Use offset when movement should follow a defined route. Use transform for direct transformations that do not require a motion path.
offset Example
This example animates a blue circle along a visible curved path. The path is drawn using SVG, while the element follows the same coordinates using CSS offset.
HTML Example
<div class="offset-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="moving-dot"></div>
</div>
CSS Example
.offset-demo {
position: relative;
width: 320px;
height: 180px;
max-width: 100%;
}
.offset-demo svg {
display: block;
width: 100%;
height: 100%;
}
.moving-dot {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #2563eb;
offset: path("M 20 140 Q 160 -100 300 140") 0% auto;
animation: follow-path 4s linear infinite alternate;
}
@keyframes follow-path {
to {
offset-distance: 100%;
}
}
@media (prefers-reduced-motion: reduce) {
.moving-dot {
animation: none;
}
}
The blue circle moves along the curved path while the offset-distance animation changes its position from 0% to 100%. The alternate animation direction makes it travel back along the same route.
Straight-Line Motion Example
<div class="straight-demo">
<div class="straight-dot"></div>
</div>
.straight-demo {
position: relative;
width: 300px;
height: 60px;
border-bottom: 2px dashed #94a3b8;
}
.straight-dot {
position: absolute;
top: 0;
left: 0;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #16a34a;
offset: path("M 10 30 L 290 30") 0%;
animation: straight-motion 3s linear infinite alternate;
}
@keyframes straight-motion {
to {
offset-distance: 100%;
}
}
@media (prefers-reduced-motion: reduce) {
.straight-dot {
animation: none;
}
}
The green circle follows a horizontal path. The distance changes while the path remains fixed.
Common Mistakes
Confusing offset with Physical Positioning Offsets
The offset shorthand does not replace the top, right, bottom, or left properties used with positioned elements. It controls CSS motion-path behavior.
Forgetting to Define a Path
.element {
offset-distance: 50%;
}
Without an applicable motion path, changing offset-distance alone generally does not produce visible movement.
Using Invalid SVG Path Data
.element {
offset-path: path("move right 200px");
}
The path() function requires valid SVG path-data commands, such as M, L, Q, and C.
Assuming the Shorthand Preserves Previous Longhand Values
.element {
offset-rotate: 0deg;
offset: circle(80px) 50%;
}
The shorthand resets offset-rotate to its initial value, auto. Place the desired longhand declaration after the shorthand or include the rotation in the shorthand.
Expecting Motion Paths to Change Document Flow
Motion-path positioning changes the element's visual placement without automatically moving surrounding elements.
Ignoring the Anchor Point
The point placed on the path may not be the point intended by the design. Adjust offset-anchor when the element appears incorrectly aligned.
Using the Wrong Distance Units
A percentage represents progress along the total path length. A length value represents a distance measured along the path.
Ignoring Reduced-Motion Preferences
Continuous or decorative motion can be distracting. Use prefers-reduced-motion to provide a reduced-motion alternative.
Assuming Every Motion Path Shape Has Identical Browser Support
Support for advanced basic-shape paths and related motion-path features may differ from support for the commonly used path() syntax.
Important Considerations
Keep the following points in mind when using offset:
- The property is a shorthand for five CSS motion-path properties.
- It controls an element's position and orientation along a path.
- Its longhands are
offset-path,offset-distance,offset-rotate,offset-anchor, andoffset-position. - The shorthand resets omitted longhand values to their initial values.
- The property is not inherited.
- Motion paths apply to transformable elements.
offset-pathdefines the route followed by the element.offset-distancedetermines progress along the route.offset-rotatecontrols orientation relative to the path.offset-anchordetermines which point of the element follows the path.offset-positionestablishes the starting reference position for the path.- SVG
path()data can define straight lines and complex curves. - CSS basic shapes can also define motion paths where supported.
- Percentage distances are relative to the path's length.
- Closed paths can support repeated movement around the route.
- Automatic rotation can align directional elements with the path tangent.
- Motion-path positioning does not automatically rearrange document flow.
- The property can be combined with CSS transforms.
- Animating
offset-distanceis a common technique for creating motion-path animations. - Use reduced-motion alternatives for nonessential animations.
- Check compatibility for newer motion-path syntax and advanced shapes.
- Test path coordinates, anchor placement, and element dimensions together.
Browser Support
The CSS offset shorthand is Baseline - Widely available for its established motion-path functionality. It is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.
Support for individual motion-path features may vary. Common functionality such as offset-path with path(), offset-distance, and offset-rotate has broader support than some newer positioning and basic-shape features.
For current compatibility information, visit Can I Use? and search for CSS motion path or the individual offset properties.
When using advanced syntax, verify support for each longhand and path type required by the design.
Specifications
The offset shorthand is defined in CSS Motion Path Module Level 1.
CSS Motion Path Module Level 1: The offset Shorthand
The specification defines motion paths, path distances, rotation, anchor points, and the shorthand syntax used to combine these properties.
For additional documentation and examples, consult MDN Web Docs.
