The offset shorthand, broken down
CSS offers many ways to place and orient an element — the position property with its inset-* counterparts, translate, margin, or anchor() where browser support permits. The offset property is another entry on that list. It is most often seen driving motion along a fixed path, and a single point on a path is all you need: because offset can position an element anywhere along a given path, it also serves as a placement tool, not only an animation one. The path may come from SVG shapes or CSS shape functions, or from the reference boxes of the containing element.
The shorthand composes five properties:
offset-position— the path's starting point;offset-path— the shape the element travels;offset-distance— how far along the path the element sits;offset-rotate— the element's rotation relative to its anchor point and the path;offset-anchor— the point inside the element that is aligned to the path.
Boxes as paths
Reference boxes correspond to an element's dimensions under the CSS Box Model — content-box, padding-box and border-box — plus the SVG contexts view-box, fill-box and stroke-box. Used as an offset-path, a box makes the surrounding perimeter a placeable track. In the demo below, the small squares sit at the default top-left of their containers' content-box, while the circles land on the top-right corner — 25% of the way around the square's perimeter — of the content-box, border-box and padding-box respectively.
<div class="big">
<div class="small circle"></div>
<div class="small square"></div>
<p>She sells sea shells by the seashore</p>
</div>
<div class="big">
<div class="small circle"></div>
<div class="small square"></div>
<p>She sells sea shells by the seashore</p>
</div>
<div class="big">
<div class="small circle"></div>
<div class="small square"></div>
<p>She sells sea shells by the seashore</p>
</div>
.small {
/* etc. */
position: absolute;
&.square {
offset: content-box;
border-radius: 4px;
}
&.circle { border-radius: 50%; }
}
.big {
/* etc. */
contain: layout; /* (or position: relative) */
&:nth-of-type(1) {
.circle { offset: content-box 25%; }
}
&:nth-of-type(2) {
border: 20px solid rgb(170 232 251);
.circle { offset: border-box 25%; }
}
&:nth-of-type(3) {
padding: 20px;
.circle { offset: padding-box 25%; }
}
}
The positioned elements here are taken out of flow with position: absolute, giving them their own layout context so that no space is reserved for them inside the parent and the paragraph text can sit flush against its edges.
<div class="circle">
<div class="square"></div>
</div>
@property --p {
syntax: '<percentage>';
inherits: false;
initial-value: 0%;
}
.square {
offset: top 50% right 50% circle(50%) var(--p);
transition: --p 1s linear;
/* Equivalent to:
offset-position: top 50% right 50%;
offset-path: circle(50%);
offset-distance: var(--p); */
/* etc. */
}
.circle:hover .square{ --p: 100%; }
The example opening this section also uses a registered custom property, --p, to set and animate the offset distance. Once you can put an element at any point of a path, animating that point is mostly bookkeeping.
Text around the edge of a block
Peripheral UI details — notification dots, ornamental ribbon tips — become straightforward with reference-box paths, and so does text. offset-rotate lets the element turn with the path, so a label can follow an edge rather than just sit beside it. In the following example, an article's date runs along the right edge of its block and is rotated 90 degrees from its bottom-left corner, which is where offset-anchor comes in: it defines the point of the element from which displacement and rotation are measured.
<article>
<h1>The Irreplaceable Value of Human Decision-Making in the Age of AI</h1>
<!-- paragraphs -->
<div class="date">Published on 11<sup>th</sup> Dec</div>
<cite>An excerpt from the HBR article</cite>
</article>
article {
container-type: inline-size;
/* etc. */
}
.date {
offset: padding-box 100cqw 90deg / left 0 bottom -10px;
/*
Equivalent to:
offset-path: padding-box;
offset-distance: 100cqw; (100% of the container element's width)
offset-rotate: 90deg;
offset-anchor: left 0 bottom -10px;
*/
}
Combining the reference box with container units tightens the result further. The offset distance can be keyed directly to the containing element's width or height, so the label tracks the box instead of relying on hand-tuned values.
Nudging with inset values
offset-anchor also accepts inset-* values, which push the element inward or outward relative to the reference box. Supplying something like bottom -10px pulls the element's bottom edge beyond the containing element's padding-box, buying finer control over exact placement.
<figure>
<div class="big">4</div>
<div class="small">number four</div>
</figure>
.small {
width: max-content;
offset: content-box 90% -54deg / center -3rem;
/*
Equivalent to:
offset-path: content-box;
offset-distance: 90%;
offset-rotate: -54deg;
offset-anchor: center -3rem;
*/
font-size: 1.5rem;
color: navy;
}
Motion without extra machinery
Since the offset distance is animatable, the same setup yields dynamic effects. The square below follows a circular path, its position driven through the registered --p property rather than a bespoke keyframe track.
<article>
<figure>
<div class="small one">17<sup>th</sup> Jan. 2025</div>
<span class="big">Seminar<br>on<br>Literature</span>
<div class="small two">Tickets Available</div>
</figure>
</article>
@property --d {
syntax: "<percentage>";
inherits: false;
initial-value: 0%;
}
.small {
/* other style rules */
offset: content-box var(--d) 0deg / left center;
/*
Equivalent to:
offset-path: content-box;
offset-distance: var(--d);
offset-rotate: 0deg;
offset-anchor: left center;
*/
transition: --d .2s linear;
&.one { --d: 2%; }
&.two { --d: 70%; }
}
article:hover figure {
.one { --d: 15%; }
.two { --d: 80%; }
}
Text along borders, textual annotations, even error messages that need to appear at a particular spot: all are one offset declaration away. Position, rotation and animation against the containing element's reference boxes come from the same feature.
Further reading
offset-path: CSS-Tricks, MDNoffset-anchor: CSS-Tricks, MDN- Container query length units: CSS-Tricks, MDN
- The
@propertyat-rule: CSS-Tricks, web.dev - The CSS Box Model: CSS-Tricks
- SVG reference boxes: W3C



