How Modern CSS Anchor Positioning Replaces Popper.js (Zero JavaScript)
For years, whenever you needed a tooltip or dropdown that dynamically stays attached to a button and flips when hitting the screen edge, you reached for getBoundingClientRect(), scroll listeners, or libraries like Popper.js / Floating UI.
With CSS Anchor Positioning (Chrome/Edge 125+, Safari 26+), this entire problem is solved in pure CSS.
The Mental Model: Boat & Dock
Think of the button as a Dock and the floating tooltip as a Boat:
-
anchor-name: --dock-btn;(assigns an anchor identifier to the target) -
position-anchor: --dock-btn;(tethers the floating element) -
top: anchor(bottom);(positions it relative to the dock edges) -
position-try-fallbacks: flip-block, flip-inline;(the browser automatically calculates viewport collisions and flips the element to open space!)
4 Real UI Patterns You Can Build Without JavaScript:
- Self-Centered Tooltips across separate DOM containers: Using
justify-self: anchor-center. - Collision Auto-Flipping: Using
@position-tryor keyword presets likeflip-block. - Dynamic Width Matching: Setting
width: anchor-size(width)so a dropdown automatically resizes to match the search bar above it. - Zero-JS Click Menus: Pairing the native HTML
popoverandpopovertargetattributes withinset: auto.
I put together an animated visual explainer breaking down these 4 patterns with live DOM inspection and code walkthroughs:
If you want to practice, I also created an open-source 60-second coding challenge with starter HTML and tests on GitHub:
https://github.com/muneebali500/cascadedev-code-vault/tree/main/01-CSS/03-anchor-positioning
How are you approaching browser support today? Are you using the OddBird polyfill or progressively enhancing with @supports (anchor-name: --a)?