CSS offset-position Property
The CSS offset-position property specifies the starting position used to place an element's motion path within its containing block.
It accepts position keywords, percentages, and lengths, allowing a motion path to begin at a particular location. The property works with offset-path, offset-distance, and other CSS motion-path properties to control how an element is positioned and animated.
offset-position Syntax
The offset-position property accepts the keyword normal or a CSS position value consisting of keywords, percentages, lengths, or combinations of these values.
Basic Syntax
selector {
offset-position: center;
}
Keyword Values
.element {
offset-position: normal;
}
.element {
offset-position: center;
}
.element {
offset-position: left top;
}
.element {
offset-position: right bottom;
}
Percentage Values
.element {
offset-position: 50% 50%;
}
.element {
offset-position: 25% 75%;
}
.element {
offset-position: 100% 0%;
}
Length Values
.element {
offset-position: 100px 50px;
}
.element {
offset-position: 5rem 3rem;
}
Mixed Values
.element {
offset-position: left 40px;
}
.element {
offset-position: 25% 100px;
}
Edge Offsets
.element {
offset-position: right 20px bottom 30px;
}
Calculated Values
.element {
offset-position: calc(50% + 20px) 50%;
}
CSS-Wide Keywords
.element {
offset-position: initial;
}
.element {
offset-position: inherit;
}
.element {
offset-position: unset;
}
.element {
offset-position: revert;
}
.element {
offset-position: revert-layer;
}
The initial value is normal, which allows the starting position to be determined by the motion-path rules and the element's existing layout position.
Property Values
| Value | Description |
|---|---|
normal |
Uses the default starting-position behavior defined for the selected motion path. |
center |
Specifies the center of the reference area. |
left |
Specifies the left edge of the reference area. |
right |
Specifies the right edge of the reference area. |
top |
Specifies the top edge of the reference area. |
bottom |
Specifies the bottom edge of the reference area. |
<percentage> |
Specifies a coordinate relative to the reference area's dimensions. |
<length> |
Specifies a coordinate using a CSS length. |
calc() |
Calculates coordinates using compatible lengths and percentages. |
initial |
Resets the property to normal. |
inherit |
Uses the computed value from the parent element. |
unset |
Resets the property to normal 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 | normal |
| Inherited | No |
| Applies to | Transformable elements |
| Computed value | As specified, with applicable length conversions |
| Animation type | By computed value type |
| Related shorthand | offset |
How It Works
The offset-position property establishes a starting position for applicable motion paths.
The browser resolves the specified position against the relevant reference area, then uses the motion-path geometry and other offset properties to determine the element's final position.
Step 1: Establish a Reference Area
.container {
position: relative;
width: 300px;
height: 200px;
}
The container provides the positioning context for its absolutely positioned child.
Step 2: Define a Starting Position
.element {
position: absolute;
offset-position: center;
}
The starting position is specified at the center of the relevant reference area.
Step 3: Define a Motion Path
.element {
position: absolute;
offset-position: center;
offset-path: ray(90deg closest-side);
}
The ray begins at the selected starting position and extends toward the right.
Step 4: Set the Distance
.element {
position: absolute;
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 50%;
}
The element is positioned halfway along the calculated ray.
Important Consideration
The effect of offset-position depends on the type of motion path. Some path types use their own coordinate system and do not use the property in the same way as a ray.
Keyword Values
Position keywords identify common locations within the reference area.
Center
.element {
offset-position: center;
}
The starting position is at the center of the reference area.
Top Left
.element {
offset-position: left top;
}
The starting position is at the top-left corner.
Top Right
.element {
offset-position: right top;
}
The starting position is at the top-right corner.
Bottom Left
.element {
offset-position: left bottom;
}
The starting position is at the bottom-left corner.
Bottom Right
.element {
offset-position: right bottom;
}
The starting position is at the bottom-right corner.
Mixed Keywords
.element {
offset-position: center top;
}
The starting position is horizontally centered along the top edge.
Important Consideration
Keyword values describe coordinates within the reference area. They do not specify how far the element travels along the path.
Percentage Values
Percentage values specify coordinates relative to the width and height of the relevant reference area.
Center Position
.element {
offset-position: 50% 50%;
}
The starting position is at the center of the reference area.
Top-Left Position
.element {
offset-position: 0% 0%;
}
The starting position is at the top-left corner.
Bottom-Right Position
.element {
offset-position: 100% 100%;
}
The starting position is at the bottom-right corner.
Custom Position
.element {
offset-position: 25% 75%;
}
The starting position is one-quarter of the way across and three-quarters of the way down the reference area.
Percentage Position Table
| Value | Position |
|---|---|
0% 0% |
Top left |
50% 0% |
Top center |
100% 0% |
Top right |
0% 50% |
Middle left |
50% 50% |
Center |
100% 50% |
Middle right |
0% 100% |
Bottom left |
50% 100% |
Bottom center |
100% 100% |
Bottom right |
Important Consideration
Percentages in offset-position represent coordinates within a reference area. Percentages in offset-distance represent progress along the path's length.
Length Values
Length values specify starting-position coordinates using CSS units such as pixels, rems, and ems.
Pixel Coordinates
.element {
offset-position: 100px 50px;
}
The starting position is 100 pixels from the left and 50 pixels from the top of the reference area.
Root Font Units
.element {
offset-position: 5rem 3rem;
}
The coordinates are calculated using the root element's font size.
Mixed Length and Percentage
.element {
offset-position: 50% 40px;
}
The starting position is horizontally centered and 40 pixels from the top.
Calculated Position
.element {
offset-position: calc(50% + 20px) 50%;
}
The starting position is shifted 20 pixels to the right of the horizontal center.
Negative Coordinates
.element {
offset-position: -20px 50%;
}
The starting position is 20 pixels outside the left edge of the reference area.
Important Consideration
Length values are useful for precise placement, while percentage values can adapt more naturally when the reference area's dimensions change.
Edge Offsets
The four-value position syntax allows coordinates to be measured from specific edges of the reference area.
Right and Bottom Offsets
.element {
offset-position: right 20px bottom 30px;
}
The starting position is 20 pixels from the right edge and 30 pixels from the bottom edge.
Left and Top Offsets
.element {
offset-position: left 40px top 25px;
}
The starting position is 40 pixels from the left edge and 25 pixels from the top edge.
Right and Top Offsets
.element {
offset-position: right 10% top 20px;
}
The starting position is 10% of the reference width inward from the right edge and 20 pixels from the top.
Bottom and Left Offsets
.element {
offset-position: bottom 15px left 50px;
}
The starting position is 15 pixels above the bottom edge and 50 pixels from the left.
Important Consideration
Edge-relative syntax is useful when the starting point should remain a fixed distance from a particular edge as the reference area changes size.
The normal Value
The normal keyword is the initial value of offset-position.
It leaves the starting position to the default behavior associated with the selected motion path, rather than explicitly choosing coordinates.
Default Value
.element {
offset-position: normal;
}
Normal with an SVG Path
.element {
offset-position: normal;
offset-path: path("M 0 0 L 200 0");
}
The SVG path uses its defined coordinates and the normal motion-path positioning rules.
Normal with a Ray
.element {
offset-position: normal;
offset-path: ray(90deg closest-side);
}
The ray uses the default starting-position behavior rather than a custom coordinate.
Explicit Starting Position
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
}
The ray starts at the center of the reference area.
Important Consideration
normal should not be treated as a universal synonym for center. Its effect depends on the type of motion path and applicable positioning rules.
Using offset-path
The offset-path property defines the motion route, while offset-position establishes the starting position for path types that use it.
Ray from the Center
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 50%;
}
The element is positioned halfway along a ray extending to the right from the center.
Ray from the Top Left
.element {
offset-position: left top;
offset-path: ray(135deg farthest-side);
offset-distance: 50%;
}
The ray extends diagonally down and right from the top-left corner.
Ray from a Custom Coordinate
.element {
offset-position: 25% 75%;
offset-path: ray(45deg closest-side);
offset-distance: 50%;
}
The ray starts one-quarter across and three-quarters down the reference area.
Using path()
.element {
offset-position: center;
offset-path: path("M 0 0 L 200 0");
offset-distance: 50%;
}
The traditional path() function defines its own SVG coordinate geometry. Unlike a ray, it does not use offset-position to relocate its starting point in the same way.
Important Consideration
Use offset-position primarily when the chosen path type supports an independently positioned starting point. For traditional SVG paths, adjust the path coordinates to change the route's location.
Positioning Ray Paths
The ray() function is particularly useful with offset-position because it defines a straight route extending from a configurable starting point.
Ray to the Right
.element {
offset-position: center;
offset-path: ray(90deg farthest-side);
offset-distance: 50%;
}
The ray extends horizontally to the right.
Ray Downward
.element {
offset-position: center;
offset-path: ray(180deg farthest-side);
offset-distance: 50%;
}
The ray extends vertically downward.
Ray to the Left
.element {
offset-position: center;
offset-path: ray(270deg farthest-side);
offset-distance: 50%;
}
The ray extends horizontally to the left.
Ray Upward
.element {
offset-position: center;
offset-path: ray(0deg farthest-side);
offset-distance: 50%;
}
The ray extends vertically upward.
Ray from a Custom Starting Point
.element {
offset-position: 40px 60px;
offset-path: ray(90deg farthest-side);
offset-distance: 75%;
}
The ray begins at the specified coordinate and extends to the right.
Ray Angle Reference
| Angle | Direction |
|---|---|
0deg |
Up |
90deg |
Right |
180deg |
Down |
270deg |
Left |
Important Consideration
Ray length is determined by the selected sizing keyword and the reference area. Changing offset-position can also change the ray's calculated length.
Using offset-distance
The offset-distance property determines how far the element travels along the path from its starting point.
Beginning of the Ray
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 0%;
}
The element is positioned at the ray's starting point.
Halfway Along the Ray
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 50%;
}
The element is positioned halfway along the calculated ray length.
End of the Ray
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 100%;
}
The element is positioned at the ray's endpoint.
Fixed Distance
.element {
offset-position: 50px 50px;
offset-path: ray(90deg farthest-side);
offset-distance: 100px;
}
The element travels 100 pixels along the ray, subject to the path's endpoint rules.
Important Consideration
offset-position determines where the path begins, while offset-distance determines progress along that path.
Using offset-anchor
The offset-anchor property specifies which point within the element is attached to the motion path.
Center Anchor
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 50%;
offset-anchor: center;
}
The element's center is attached to the calculated path position.
Top-Left Anchor
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 50%;
offset-anchor: left top;
}
The element's top-left corner is attached to the path.
Custom Anchor
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 50%;
offset-anchor: 25% 75%;
}
A custom point within the element is attached to the path.
Important Consideration
offset-position establishes a path position, while offset-anchor identifies the point within the moving element that follows the route.
Using the offset Shorthand
The offset shorthand combines several motion-path properties into a single declaration.
Longhand Version
.element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 50%;
offset-rotate: 0deg;
offset-anchor: center;
}
Shorthand Version
.element {
offset: center ray(90deg closest-side) 50% 0deg / center;
}
The shorthand specifies the starting position, path, distance, rotation, and anchor.
Position and Path
.element {
offset: left top ray(135deg farthest-side);
}
The shorthand establishes a ray beginning at the top-left position.
Position, Path, and Distance
.element {
offset: center ray(90deg closest-side) 75%;
}
The element is positioned three-quarters of the way along the ray.
Shorthand Reset Behavior
.element {
offset-position: right bottom;
offset: ray(90deg closest-side);
}
The shorthand resets offset-position to normal because the position is omitted.
Preserving a Custom Position
.element {
offset: ray(90deg closest-side);
offset-position: right bottom;
}
Declaring the longhand after the shorthand preserves the intended starting position.
Animating offset-position
The offset-position property can be animated between compatible position values, allowing the starting point of a motion path to move over time.
Horizontal Starting-Point Animation
.moving-element {
offset-position: 20% 50%;
offset-path: ray(90deg closest-side);
offset-distance: 0%;
animation: move-start 4s ease-in-out infinite alternate;
}
@keyframes move-start {
to {
offset-position: 80% 50%;
}
}
The starting point moves horizontally between two percentage coordinates.
Vertical Starting-Point Animation
.moving-element {
offset-position: 50% 20%;
offset-path: ray(90deg closest-side);
offset-distance: 0%;
animation: move-start 4s ease-in-out infinite alternate;
}
@keyframes move-start {
to {
offset-position: 50% 80%;
}
}
The starting point moves vertically within the reference area.
Animating Path Progress Instead
.moving-element {
offset-position: center;
offset-path: ray(90deg closest-side);
offset-distance: 0%;
animation: move-distance 3s linear infinite alternate;
}
@keyframes move-distance {
to {
offset-distance: 100%;
}
}
This animation keeps the starting position fixed while moving the element along the ray.
Reduced Motion
@media (prefers-reduced-motion: reduce) {
.moving-element {
animation: none;
}
}
The media query disables nonessential movement for users who request reduced motion.
Important Consideration
Animating the starting position and animating the distance produce different effects. The first moves the path's origin, while the second moves the element along the path.
Responsive Layouts
Percentage-based positions can help motion paths adapt to changes in the dimensions of their reference area.
Centered Starting Position
.element {
offset-position: 50% 50%;
offset-path: ray(90deg closest-side);
}
The starting point remains centered as the reference area changes size.
Edge-Relative Starting Position
.element {
offset-position: right 20px bottom 20px;
offset-path: ray(270deg closest-side);
}
The starting point remains a fixed distance from the right and bottom edges.
Media Query Adjustment
.element {
offset-position: 75% 50%;
offset-path: ray(90deg closest-side);
}
@media (max-width: 767px) {
.element {
offset-position: 50% 75%;
}
}
The starting position changes on smaller screens.
Custom Property
.element {
--start-x: 50%;
--start-y: 50%;
offset-position: var(--start-x) var(--start-y);
offset-path: ray(90deg closest-side);
}
CSS custom properties can make the starting coordinates easier to update.
Important Consideration
Responsive positioning depends on the reference area used by the motion path. Verify that the containing block and path geometry behave as expected at different viewport sizes.
offset-position Example
This example demonstrates three different starting positions for horizontal ray paths. Each marker uses the same direction and distance, but a different offset-position value.
HTML Example
<div class="position-demo">
<div class="position-marker marker-top">1</div>
<div class="position-marker marker-center">2</div>
<div class="position-marker marker-bottom">3</div>
</div>
CSS Example
.position-demo {
position: relative;
width: 320px;
height: 200px;
max-width: 100%;
border: 1px solid #cbd5e1;
background-color: #f8fafc;
}
.position-marker {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
border-radius: 50%;
color: #fff;
font-size: 14px;
font-weight: 600;
offset-path: ray(90deg farthest-side);
offset-distance: 0%;
offset-anchor: center;
offset-rotate: 0deg;
}
.marker-top {
background-color: #2563eb;
offset-position: 25% 20%;
}
.marker-center {
background-color: #16a34a;
offset-position: 50% 50%;
}
.marker-bottom {
background-color: #dc2626;
offset-position: 75% 80%;
}
The blue marker begins at 25% 20%, the green marker at 50% 50%, and the red marker at 75% 80%. Since offset-distance is 0%, each marker remains at its ray's starting point.
Animated Starting Position Example
The following example animates the starting point of a ray horizontally across its reference area.
<div class="animated-position-demo">
<div class="animated-position-marker"></div>
</div>
.animated-position-demo {
position: relative;
width: 320px;
height: 120px;
border: 1px solid #cbd5e1;
}
.animated-position-marker {
position: absolute;
top: 0;
left: 0;
width: 24px;
height: 24px;
border-radius: 50%;
background-color: #2563eb;
offset-position: 20% 50%;
offset-path: ray(90deg closest-side);
offset-distance: 0%;
offset-anchor: center;
offset-rotate: 0deg;
animation: shift-origin 4s ease-in-out infinite alternate;
}
@keyframes shift-origin {
to {
offset-position: 80% 50%;
}
}
@media (prefers-reduced-motion: reduce) {
.animated-position-marker {
animation: none;
}
}
The marker moves because its path's starting position changes. Its offset-distance remains at 0% throughout the animation.
Common Mistakes
Confusing offset-position with offset-distance
offset-position specifies a starting position. offset-distance determines progress along the path.
Assuming normal Means center
The normal keyword follows the default positioning behavior for the selected motion path. It is not always equivalent to center.
Expecting Every Path Type to Respond Equally
Some path types establish their own coordinate geometry. The effect of offset-position depends on the selected offset-path value.
Using offset-position Without an Applicable Path
.element {
offset-position: right bottom;
}
Without an applicable motion path, the declaration may not produce a visible positioning change.
Confusing Percentages with Path Progress
Percentages in offset-position describe coordinates, not progress along a motion path.
Ignoring the Reference Area
The resolved starting position depends on the dimensions and positioning context of the applicable reference area.
Ignoring the Anchor Point
The element's visual position also depends on offset-anchor.
Forgetting Shorthand Reset Behavior
.element {
offset-position: center;
offset: ray(90deg closest-side);
}
The shorthand resets offset-position to normal because no starting position is included.
Using Invalid Angle Values
.element {
offset-position: 45deg;
}
Angles are not valid position values. Use angles within functions such as ray(), not as standalone offset-position values.
Ignoring Browser Compatibility
offset-position has more limited browser support than some other motion-path properties. Test the specific combinations required by your project.
Important Considerations
Keep the following points in mind when using offset-position:
- The property specifies the starting position for applicable CSS motion paths.
- Its initial value is
normal. - The property is not inherited.
- It applies to transformable elements.
- It is a longhand property of the
offsetshorthand. - It accepts CSS position keywords, lengths, and percentages.
- It supports edge-relative positioning syntax.
- Calculated positions can use
calc(). - The
normalkeyword uses default motion-path positioning behavior. - The effect depends on the type of motion path.
- The property is especially useful with
ray()paths. - Traditional
path()geometry uses its own SVG coordinates. - Percentage coordinates depend on the relevant reference area's dimensions.
- Length coordinates specify fixed distances from the applicable origin or edge.
- Negative position coordinates are permitted.
offset-distancecontrols progress along the path.offset-anchorcontrols which point of the element follows the path.offset-rotatecontrols the element's orientation.- Changing the starting position can also affect the length of a ray path.
- Position values can be animated when their computed types are compatible.
- Percentage-based coordinates can adapt to responsive layouts.
- Motion-path positioning does not automatically rearrange surrounding document flow.
- The
offsetshorthand resets omitted motion-path longhands. - Browser support is more limited than for established motion-path features such as
offset-distance. - Test the complete path, starting position, distance, anchor, and rotation together.
Browser Support
The CSS offset-position property has Limited availability and is not part of the Baseline - Widely available feature set.
Support varies among browsers and versions. Although established CSS motion-path properties are broadly supported, offset-position and some newer path-positioning features may not be available in every browser.
For current compatibility information, visit Can I Use? and search for offset-position.
When compatibility is important, test the property in the browsers required by your project. Consider using explicit path coordinates or established positioning techniques when support is insufficient.
Specifications
The offset-position property is defined in CSS Motion Path Module Level 1.
CSS Motion Path Module Level 1: The offset-position Property
The specification defines how starting positions are resolved for applicable motion paths and how the property interacts with other motion-path positioning features.
For additional documentation and examples, consult MDN Web Docs.
