Under The Hood
frontend css CSS Anchor Positioning (Chrome 125+)

Anchor Positioning: anchor-name Tethering Without JS Math

Last updated
Prerequisites:
CSS positioning (absolute/fixed)
Understanding of inset properties and overflow
  • css
  • anchor-positioning
  • anchor-name
  • position-anchor
  • popover
  • tooltip

Read at your depth

The practical view

Anchor positioning lets you attach an element to another element (the anchor) without JavaScript. Mark the anchor: .btn { anchor-name: --tip; } then position the popover: .popover { position: absolute; position-anchor: --tip; left: anchor(right); bottom: anchor(top); }. inset-area: top right; is a shorthand that places the element in a named region around the anchor. Anchor functions (anchor(edge), anchor(--name edge)) resolve to the anchor's edges. This replaces manual getBoundingClientRect + coordinates math for tooltips, menus, and callouts.

The same idea in other frameworks

react equivalent
React tooltip/menu components can drop floating-ui geometry math for CSS anchor positioning where browser support allows.

Legacy vs modern

getBoundingClientRect math vs anchor positioning

JS geometry must be recomputed on scroll/resize; CSS anchor positioning keeps the popover tethered automatically via the layout engine.

before → after
Manual JS positioning math
const r = btn.getBoundingClientRect();
pop.style.left = r.right + 'px'; pop.style.top = r.top + 'px'; // ❌ OLD
CSS anchor positioning
.btn { anchor-name: --tip; }
.popover { position: absolute; position-anchor: --tip; inset-area: right; } /* ✅ NEW */

Interview gotchas

Context

This tests whether you understand that anchor positioning is resolved by the layout engine, not computed once — the key architectural difference from manual geometry math.

The mechanical answer

The anchored element's position is recomputed as part of the layout/rendering pipeline: the engine resolves the anchor() inset values against the registered anchor's current border box at each render update. When the page scrolls or the anchor moves (including under transforms), the anchor's box position is updated and the anchored element's insets re-resolve in the same frame — no scroll/resize listeners are involved. This is why it stays perfectly attached with zero jank risk from JS sampling. With position-try-options, the engine also re-evaluates fallback placements during the same resolution, picking the first candidate that fits the scrollport.

Trap

The naive answer is 'it computes the position once at load'. It is re-resolved continuously by the layout engine as the anchor moves. Another trap: thinking it is equivalent to position: absolute relative to a wrapper — the anchor can be anywhere in the document, including in another stacking context, and the positioned element can live in the top layer. Candidates who mention the re-resolution pipeline and the anchor registry show real understanding.

Under The Hood — a multi-depth technical interview hub.

Third-party licenses Press ⌘ K to search.