Search pages
Search all CSS Showcase pages by name
CSS Anchor Positioning
Position elements relative to other elements without JavaScript. The Anchor Positioning API brings tooltips, popovers, and dropdown menus into pure CSS.
The Problem Anchor Positioning Solves
For years, positioning a tooltip next to a button or a dropdown below an input required JavaScript. You’d calculate positions, handle scrolling, deal with viewport edges — it was a nightmare. Anchor Positioning changes everything.
anchor-nameDefines an element as an anchor point that other elements can reference.
position-anchorLinks a positioned element to a named anchor, creating the relationship.
anchor()Function that references anchor edges — top, bottom, left, right, or centre.
Basic Positioning
Position tooltips, badges, and notifications relative to any element. Hover each button to see a tooltip appear in a different direction.
Real-World Examples
Anchor positioning shines in common UI patterns. Here are two practical examples you can build with CSS alone.
Browser Support
CSS Anchor Positioning is a cutting-edge feature. Use feature detection to provide fallbacks for browsers that don’t support it yet.
Cutting-Edge Feature
CSS Anchor Positioning is brand new!
- Chrome 125+: Supported
- Firefox: In development
- Safari: In development
For production: Use JavaScript fallbacks or wait for broader support. Consider using a polyfill or CSS feature detection with @supports.
Why This Matters
Anchor Positioning removes the need for thousands of lines of JavaScript positioning logic. It’s all declarative CSS now.
Calculating element positions with getBoundingClientRect()
Handling scroll events to reposition tooltips
Detecting viewport edges and flipping positions
Heavy libraries like Popper.js for simple tooltips
Keep Learning
Explore other modern CSS features that pair brilliantly with anchor positioning.