CSS offset-anchor Property
The CSS offset-anchor property specifies which point within an element is positioned on its CSS motion path.
It determines how the element is attached to the path, allowing its center, corners, edges, or a custom point to follow the route. The property works with offset-path, offset-distance, and offset-rotate to control motion-path positioning and orientation.
offset-anchor Syntax
The offset-anchor property accepts the keyword auto or position values that identify a point within the element's reference box.
Basic Syntax
selector {
offset-anchor: center;
}
Keyword Values
.element {
offset-anchor: auto;
}
.element {
offset-anchor: center;
}
.element {
offset-anchor: left top;
}
.element {
offset-anchor: right bottom;
}
Percentage Values
.element {
offset-anchor: 50% 50%;
}
.element {
offset-anchor: 25% 75%;
}
Length Values
.element {
offset-anchor: 20px 10px;
}
.element {
offset-anchor: 2rem 1rem;
}
Edge-Relative Values
.element {
offset-anchor: right 10px bottom 5px;
}
CSS-Wide Keywords
.element {
offset-anchor: initial;
}
.element {
offset-anchor: inherit;
}
.element {
offset-anchor: unset;
}
.element {
offset-anchor: revert;
}
.element {
offset-anchor: revert-layer;
}
The initial value is auto. When automatic anchor positioning applies, the element normally uses the position established by its transform-origin.
Property Values
| Value | Description |
|---|---|
auto |
Uses the automatic anchor position, normally corresponding to the element's transform-origin. |
left |
Selects the left edge of the reference box. |
right |
Selects the right edge of the reference box. |
top |
Selects the top edge of the reference box. |
bottom |
Selects the bottom edge of the reference box. |
center |
Selects the center along the applicable axis. |
<percentage> |
Specifies a point as a percentage of the element's reference box dimensions. |
<length> |
Specifies a point using length offsets from the applicable edges. |
initial |
Resets the property to auto. |
inherit |
Uses the computed value from the parent element. |
unset |
Resets the property to auto 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 | auto |
| Inherited | No |
| Applies to | Transformable elements |
| Computed value | As specified, with relative lengths converted to absolute lengths |
| Animation type | By computed value type |
| Related shorthand | offset |
How It Works
The offset-anchor property identifies a point within an element that should coincide with its calculated position on a motion path.
The browser first determines the element's position along the path using offset-path and offset-distance. It then aligns the specified anchor point with that path position.
Center Anchor
.element {
width: 60px;
height: 60px;
offset-path: path("M 0 0 L 200 0");
offset-distance: 50%;
offset-anchor: center;
}
The center of the 60-by-60-pixel element is placed halfway along the path.
Top-Left Anchor
.element {
width: 60px;
height: 60px;
offset-path: path("M 0 0 L 200 0");
offset-distance: 50%;
offset-anchor: left top;
}
The element's top-left corner is placed at the same point on the path.
Bottom-Right Anchor
.element {
width: 60px;
height: 60px;
offset-path: path("M 0 0 L 200 0");
offset-distance: 50%;
offset-anchor: right bottom;
}
The element's bottom-right corner is aligned with the path position.
Visual Difference
All three examples use the same path and distance. Only the point attached to the path changes, producing different visual placements.
Important Consideration
The anchor is a point within the element, not a separate point along the path. Changing offset-anchor does not change the path geometry or the distance traveled.
Keyword Anchors
Keyword values provide convenient ways to attach an element's center, edges, or corners to a motion path.
Center
.element {
offset-anchor: center;
}
The center of the element's reference box is placed on the path.
Top-Left Corner
.element {
offset-anchor: left top;
}
The top-left corner is attached to the path.
Top-Right Corner
.element {
offset-anchor: right top;
}
The top-right corner is attached to the path.
Bottom-Left Corner
.element {
offset-anchor: left bottom;
}
The bottom-left corner is attached to the path.
Bottom-Right Corner
.element {
offset-anchor: right bottom;
}
The bottom-right corner is attached to the path.
Edge Centers
.element {
offset-anchor: center top;
}
.element {
offset-anchor: center bottom;
}
.element {
offset-anchor: left center;
}
.element {
offset-anchor: right center;
}
These values attach the midpoint of a selected edge to the path.
Single Keyword
.element {
offset-anchor: top;
}
The top edge is selected, and the unspecified horizontal position is centered.
Percentage Anchors
Percentage values specify the anchor point relative to the dimensions of the element's reference box.
Center Anchor
.element {
offset-anchor: 50% 50%;
}
The anchor is positioned halfway across and halfway down the element.
Top-Left Anchor
.element {
offset-anchor: 0% 0%;
}
The anchor is positioned at the top-left corner.
Bottom-Right Anchor
.element {
offset-anchor: 100% 100%;
}
The anchor is positioned at the bottom-right corner.
Custom Anchor
.element {
offset-anchor: 25% 75%;
}
The anchor is positioned one-quarter of the way across and three-quarters of the way down the element.
Percentage Calculation
For an element with a 200-pixel-wide and 100-pixel-tall reference box, the declaration offset-anchor: 25% 75% identifies a point 50 pixels from the left and 75 pixels from the top.
Important Consideration
Percentage anchor positions are calculated from the element's reference box, not from the total length of the motion path.
Length Anchors
Length values specify an anchor point using distances measured from the applicable edges of the element's reference box.
Pixel Values
.element {
offset-anchor: 20px 10px;
}
The anchor is positioned 20 pixels from the left edge and 10 pixels from the top edge.
Relative Lengths
.element {
offset-anchor: 2rem 1rem;
}
The anchor uses offsets based on the root element's font size.
Negative Lengths
.element {
offset-anchor: -10px 20px;
}
The anchor point is positioned 10 pixels outside the left edge and 20 pixels below the top edge of the reference box.
Calculated Values
.element {
offset-anchor: calc(50% + 10px) center;
}
The horizontal anchor is shifted 10 pixels to the right of the element's center.
Edge-Relative Offsets
.element {
offset-anchor: right 15px bottom 10px;
}
The anchor is positioned 15 pixels from the right edge and 10 pixels from the bottom edge.
Important Consideration
Length-based anchors are useful when the attachment point must remain at a fixed distance from an edge, regardless of the element's overall dimensions.
auto Value
The auto value is the initial value of offset-anchor. It normally uses the element's transform-origin as the motion-path anchor.
Default Behavior
.element {
offset-path: circle(80px);
offset-distance: 25%;
offset-anchor: auto;
}
For an ordinary HTML element with the default transform-origin: 50% 50%, the automatic anchor is the element's center.
Changing transform-origin
.element {
transform-origin: left top;
offset-path: circle(80px);
offset-distance: 25%;
offset-anchor: auto;
}
The automatic anchor follows the selected transform origin, placing the element's top-left point on the path.
Explicit Anchor
.element {
transform-origin: left top;
offset-path: circle(80px);
offset-distance: 25%;
offset-anchor: center;
}
The explicit center anchor overrides the automatic anchor selection. The transform origin can still affect other transformations.
Important Consideration
The automatic anchor can depend on the element's transform origin. Specify an explicit anchor when the attachment point must remain independent of that setting.
Using the offset Shorthand
The offset-anchor property is one of five longhand properties represented by the offset shorthand.
Longhand Version
.element {
offset-path: circle(80px);
offset-distance: 25%;
offset-rotate: auto;
offset-anchor: center;
}
Shorthand Version
.element {
offset: circle(80px) 25% auto / center;
}
The slash separates the anchor value from the preceding path, distance, and rotation values.
Top-Left Anchor
.element {
offset: circle(80px) 25% / left top;
}
The element follows the circular path with its top-left corner attached to the route.
Custom Percentage Anchor
.element {
offset: path("M 0 0 L 200 0") 50% / 25% 75%;
}
The element is positioned halfway along the horizontal path using a custom anchor point.
Shorthand Reset Behavior
.element {
offset-anchor: left top;
offset: circle(80px) 50%;
}
The shorthand resets offset-anchor to auto because no anchor is included.
Preserve a Custom Anchor
.element {
offset: circle(80px) 50%;
offset-anchor: left top;
}
Declaring the longhand after the shorthand preserves the custom anchor.
offset-anchor vs. transform-origin
The offset-anchor and transform-origin properties both identify points within an element, but they serve different purposes.
offset-anchor
.element {
offset-path: circle(80px);
offset-distance: 50%;
offset-anchor: left top;
}
The top-left point of the element is attached to the motion path.
transform-origin
.element {
transform-origin: left top;
transform: rotate(45deg);
}
The element rotates around its top-left transform origin.
Using Both Properties
.element {
transform-origin: center;
offset-path: circle(80px);
offset-distance: 50%;
offset-anchor: left top;
transform: rotate(30deg);
}
The motion-path anchor is the top-left point, while the separate transform rotation uses the center as its origin.
Comparison
| Feature | offset-anchor | transform-origin |
|---|---|---|
| Primary purpose | Defines the point attached to a motion path | Defines the origin for CSS transformations |
| Related properties | offset-path, offset-distance |
transform, rotate, scale |
| Initial value | auto |
50% 50% 0 for ordinary HTML elements |
| Can influence motion-path placement | Yes | Yes, when offset-anchor is auto |
Use offset-anchor to control the motion-path attachment point. Use transform-origin to control the origin of transformations.
Motion Path Animation
Changing the anchor point affects how an element appears while traveling along a motion path.
Center-Anchored Animation
.moving-element {
width: 30px;
height: 30px;
offset-path: path("M 0 100 Q 150 -100 300 100");
offset-distance: 0%;
offset-anchor: center;
animation: follow-path 4s linear infinite alternate;
}
@keyframes follow-path {
to {
offset-distance: 100%;
}
}
The center of the element follows the curved path.
Corner-Anchored Animation
.moving-element {
width: 30px;
height: 30px;
offset-path: path("M 0 100 Q 150 -100 300 100");
offset-distance: 0%;
offset-anchor: left top;
animation: follow-path 4s linear infinite alternate;
}
The top-left corner follows the same curve, changing the element's visible placement.
Directional Animation
.moving-arrow {
offset-path: path("M 0 100 Q 150 -100 300 100");
offset-distance: 0%;
offset-rotate: auto;
offset-anchor: left center;
animation: follow-path 4s linear infinite;
}
The arrow's left-center point follows the path while its orientation changes with the path direction.
Reduced Motion
@media (prefers-reduced-motion: reduce) {
.moving-element,
.moving-arrow {
animation: none;
}
}
This media query disables the motion for users who request reduced animation.
Important Consideration
The anchor point and automatic rotation work together. For directional graphics, choose an anchor that produces the intended visual alignment while the element rotates.
Practical Uses
The offset-anchor property is useful whenever an element must follow a path using a specific attachment point.
Center an Icon on a Path
.path-icon {
width: 32px;
height: 32px;
offset-path: circle(100px);
offset-distance: 25%;
offset-anchor: center;
}
The center of the icon follows the circular path.
Attach an Arrow by Its Tip
.path-arrow {
width: 40px;
height: 20px;
offset-path: path("M 0 0 L 250 0");
offset-distance: 50%;
offset-anchor: right center;
}
For an arrow graphic whose tip is at its right-center edge, the tip is attached to the path.
Attach a Label by Its Corner
.path-label {
width: 100px;
height: 40px;
offset-path: circle(80px);
offset-distance: 75%;
offset-anchor: left top;
}
The label's top-left corner follows the circular route.
Custom Attachment Point
.custom-marker {
width: 80px;
height: 60px;
offset-path: path("M 0 0 L 200 100");
offset-distance: 50%;
offset-anchor: 30% 80%;
}
The marker follows the path using a custom point inside its reference box.
Animated Progress Marker
.progress-marker {
offset-path: path("M 0 0 L 300 0");
offset-distance: 60%;
offset-anchor: center;
}
The marker is positioned 60% along the path with its center aligned to the route.
offset-anchor Example
This example compares three anchor positions on the same horizontal motion path. Each square is placed halfway along the route, but a different point of each square is attached to that location.
HTML Example
<div class="anchor-demo">
<div class="anchor-row">
<span>center</span>
<div class="anchor-track">
<div class="anchor-box anchor-center"></div>
</div>
</div>
<div class="anchor-row">
<span>left top</span>
<div class="anchor-track">
<div class="anchor-box anchor-top-left"></div>
</div>
</div>
<div class="anchor-row">
<span>right bottom</span>
<div class="anchor-track">
<div class="anchor-box anchor-bottom-right"></div>
</div>
</div>
</div>
CSS Example
.anchor-demo {
display: grid;
gap: 20px;
}
.anchor-row > span {
display: block;
margin-bottom: 8px;
font-weight: 600;
}
.anchor-track {
position: relative;
width: 100%;
height: 90px;
background-color: #f8fafc;
border: 1px solid #cbd5e1;
}
.anchor-track::before {
content: "";
position: absolute;
top: 45px;
left: 20px;
width: 200px;
border-top: 2px dashed #64748b;
}
.anchor-box {
position: absolute;
top: 0;
left: 0;
width: 40px;
height: 40px;
background-color: #2563eb;
offset-path: path("M 20 45 L 220 45");
offset-distance: 50%;
offset-rotate: 0deg;
}
.anchor-center {
offset-anchor: center;
}
.anchor-top-left {
offset-anchor: left top;
}
.anchor-bottom-right {
offset-anchor: right bottom;
}
Each square uses the same path and offset-distance: 50%. The center-anchored square is centered on the path position, the top-left-anchored square extends right and downward, and the bottom-right-anchored square extends left and upward.
Animated Anchor Example
<div class="motion-container">
<div class="motion-marker"></div>
</div>
.motion-container {
position: relative;
width: 320px;
height: 180px;
}
.motion-marker {
position: absolute;
top: 0;
left: 0;
width: 30px;
height: 30px;
background-color: #16a34a;
border-radius: 50%;
offset-path: path("M 20 140 Q 160 -100 300 140");
offset-distance: 0%;
offset-anchor: center;
animation: marker-motion 4s linear infinite alternate;
}
@keyframes marker-motion {
to {
offset-distance: 100%;
}
}
@media (prefers-reduced-motion: reduce) {
.motion-marker {
animation: none;
}
}
The green marker follows the curved path using its center as the attachment point.
Common Mistakes
Expecting offset-anchor to Define a Motion Path
.element {
offset-anchor: center;
}
The property only selects the attachment point. It does not define a route or cause movement by itself.
Confusing offset-anchor with offset-distance
offset-anchor selects a point within the element. offset-distance selects a position along the path.
Confusing offset-anchor with transform-origin
The properties are related but serve different purposes. The motion-path anchor controls attachment to the path, while the transform origin controls transformations.
Forgetting Shorthand Reset Behavior
.element {
offset-anchor: left top;
offset: circle(80px) 50%;
}
The shorthand resets the previously declared anchor to auto. Declare the anchor after the shorthand or include it after the slash.
Using Invalid Keyword Combinations
.element {
offset-anchor: left right;
}
Two conflicting horizontal keywords cannot define a valid position. Use a horizontal and vertical combination such as left top.
Assuming Percentages Refer to Path Length
Anchor percentages refer to the element's reference box. Path progress percentages belong to offset-distance.
Ignoring Element Dimensions
Percentage-based anchor points change when the element's reference box dimensions change.
Assuming auto Always Means Center
The automatic anchor normally follows the element's transform-origin. A custom transform origin can change the effective anchor.
Expecting the Anchor to Change Document Flow
Changing the motion-path anchor affects visual positioning, not the space reserved for surrounding layout content.
Important Considerations
Keep the following points in mind when using offset-anchor:
- The property determines which point of an element is placed on its motion path.
- Its initial value is
auto. - The property is not inherited.
- It applies to transformable elements.
- It is a longhand property of the
offsetshorthand. - It does not define the motion path itself.
- It does not determine how far the element travels along the path.
- Keyword values can select the center, edges, or corners of the element.
- Percentage values identify points relative to the element's reference box.
- Length values specify offsets from the applicable edges.
- Negative length values can place the anchor outside the reference box.
- Edge-relative syntax can measure offsets from the right or bottom edges.
- The
autovalue normally uses the element'stransform-origin. - An explicit anchor can be used independently of the transform origin.
- The shorthand syntax uses a slash before the anchor value.
- Declaring
offsetresets omitted longhand values. - Changing the anchor can visibly shift an element without changing its path or distance.
- Automatic path rotation can affect the final orientation of the anchored element.
- Percentage-based anchors can change when element dimensions change.
- Motion-path positioning does not automatically rearrange surrounding layout content.
- Check browser compatibility when using advanced motion-path features.
- Test anchor positions with the actual element dimensions and path geometry.
Browser Support
The CSS offset-anchor property has limited availability compared with established CSS positioning features. Support varies across browser versions and engines, particularly for advanced motion-path positioning.
Some browsers support common motion-path properties such as offset-path and offset-distance without supporting every related feature to the same extent.
For current compatibility information, visit Can I Use? and search for offset-anchor.
When consistent motion-path alignment is essential, test the property in the browsers required by your project and provide an appropriate fallback when necessary.
Specifications
The offset-anchor property is defined in CSS Motion Path Module Level 1.
CSS Motion Path Module Level 1: The offset-anchor Property
The specification defines how the anchor point of an element is selected and aligned with a calculated position on a motion path.
For additional documentation and examples, consult MDN Web Docs.
