CSS Anchor Positioning
CSS Anchor Positioning lets position: fixed or absolute elements tether directly to any named anchor in Render Tree & Layout. Combined with position-try-fallbacks, tooltips and menus flip away from viewport edges with zero JavaScript geometry reads.
Native Anchor & Flip Fallback Resolution
Step through how Layout binds a popover to an anchor and flips on viewport collision.
Trigger declares anchor-name: --menu-btn; tooltip binds via position-anchor: --menu-btn.
.trigger { anchor-name: --menu-btn; }
.tip { position: fixed; position-anchor: --menu-btn; }- anchorRegistered
- --menu-btn
- targetLayer
- Top Layer
Under the Hood
Instead of JavaScript calling getBoundingClientRect() after paint and patching top/left on the next frame, the layout engine solves the tether in one pass.
- Anchor Registration:
anchor-name: --triggerexposes a box's geometry to later or Top Layer elements. - Tethering:
position-anchor: --triggerwithposition-area: bottom span-right(ortop: anchor(bottom)) locks the overlay to the anchor's edges. - Collision Flip:
position-try-fallbacks: flip-block, flip-inlinetests alternative placements during Layout when the overlay overflows the viewport.
.menu-btn { anchor-name: --menu-btn; }
.menu-popover {
position: fixed;
position-anchor: --menu-btn;
position-area: bottom span-right;
position-try-fallbacks: flip-block, flip-inline;
}Pairs cleanly with Popover API and contrasts with JS Floating Positioning Engines.
Problem Genealogy
- 2010–2023: Popper.js and Floating UI had to measure rects in JS, listen to scroll/resize, and fight
overflow: hiddenclipping. - 2024–2026: CSS Anchor Positioning shipped in Chromium and Safari, with Firefox implementation underway.
Production Pitfalls
- Browser coverage gap: Firefox support is still in progress; fall back to Floating UI or feature-detect with
@supports (anchor-name: --a). - Same-name collisions in lists: Reusing
anchor-name: --rowon every table row breaks lookup; useanchor-scope: --rowon each row wrapper or inline unique names.
- When not to use CSS Anchor Positioning: If you require 100% cross-browser parity today without a polyfill, use a lightweight JS positioning engine.
Connections & Logical Next Steps
Anchor positioning resolves inset coordinates during Layout without JS getBoundingClientRect() reads.
Combines with Top Layer popovers to replace JS floating positioning libraries.
CSS Anchor Positioning moves collision flipping from JS measurement loops into native Layout.
Declarative anchor() and position-try-fallbacks replace JS getBoundingClientRect() measurement and repositioning loops.