CSS Anchor Positioning vs JS Floating Positioning Engines (Floating UI)
Declarative anchor() and position-try-fallbacks replace JS getBoundingClientRect() measurement and repositioning loops.
Structured Comparison Matrix
| Dimension | CSS Anchor Positioning | JS Floating Positioning Engines (Floating UI) |
|---|---|---|
| Mental Model | anchor-name and anchor() tether popovers and tooltips to trigger elements natively in Layout, including viewport-collision flips. | Floating positioning engines compute coordinates via getBoundingClientRect() and middleware pipelines (flip, shift, offset) synced to scroll and resize. |
| Maturity & Domain | Experimental · CSS & Layout Chrome 125+ · Firefox In development · Safari 26+ | Baseline · Widely · CSS & Layout Chrome 51+ · Firefox 53+ · Safari 10+ |
| Prerequisites | ||
| 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. | When not to use a JS positioning engine: For static centered modals, use Native <dialog>; in Chromium/Safari-only apps, prefer native CSS Anchor Positioning. |
Engine Mechanics & Trade-Offs
Engine lays out the anchor first, resolves anchor() insets on the positioned element, and tries position-try-fallbacks if it overflows the containing block.
Key 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: --row on every table row breaks lookup; use anchor-scope: --row on each row wrapper or inline unique names.
computePosition reads reference and floating DOMRects, runs collision middleware in JS, and writes translate3d() coordinates.
Key Pitfalls: Forgetting cleanup(): Leaving autoUpdate() active after a popover closes leaks scroll and ResizeObserver listeners. Subpixel blur on odd dimensions: Unrounded x/y values in translate3d() blur 1px borders and text; round to Math.round(x) or DPR multiples.