CSS & LayoutExperimental

CSS Anchor Positioning

Mental Model

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.

Interactive Simulator

Native Anchor & Flip Fallback Resolution

Step through how Layout binds a popover to an anchor and flips on viewport collision.

anchor-name
position-area
flip-block
Step 1 / 3: 1. Register Anchor & Target

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; }
Internal State / Memory
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.

  1. Anchor Registration: anchor-name: --trigger exposes a box's geometry to later or Top Layer elements.
  2. Tethering: position-anchor: --trigger with position-area: bottom span-right (or top: anchor(bottom)) locks the overlay to the anchor's edges.
  3. Collision Flip: position-try-fallbacks: flip-block, flip-inline tests alternative placements during Layout when the overlay overflows the viewport.
CSS
.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: hidden clipping.
  • 2024–2026: CSS Anchor Positioning shipped in Chromium and Safari, with Firefox implementation underway.

Production Pitfalls

Production Pitfall
  • 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: --row on every table row breaks lookup; use anchor-scope: --row on each row wrapper or inline unique names.
When Not to Use
  • 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

Seen in Architecture Autopsies

Mechanical Comparisons