Tevpro insights
CSS Anchor Positioning for Tooltips and Popovers
Build a working anchored popover with CSS anchor positioning, native popover behavior, and a fallback for browsers without anchor support.
Key takeaways
- CSS anchor positioning tethers a floating element to a named trigger without reading its coordinates in supporting browsers.
- The Popover API controls opening and Escape; anchor positioning only controls placement. A small measurement fallback can be isolated to older engines.
- Test viewport edges, scrolling, focus, and zoom before replacing a full-featured positioning library.
A popover has two separate jobs: it must open and close, and it must stay beside its trigger. The Popover API handles the first job; CSS anchor positioning handles the second.
1. Give the trigger a real popover target
<button id="actions" popovertarget="menu">Actions</button>
<div id="menu" popover>
<button type="button">Edit</button>
</div>
The popovertarget attribute opens the panel on click. The browser also handles Escape and light-dismiss behavior. Nothing in this markup specifies where the panel appears.
2. Name the anchor and position the panel
@supports (anchor-name: --actions) and (position-area: bottom) {
#actions { anchor-name: --actions; }
#menu:popover-open {
position: absolute;
position-anchor: --actions;
position-area: bottom;
inset: auto;
margin: .5rem 0 0;
}
}
anchor-name names the trigger. position-anchor connects the open panel to it; position-area: bottom places it beneath the trigger. The panel follows its anchor while scrolling without reading getBoundingClientRect() on every scroll.
3. Decide what unsupported browsers should do
The @supports block is skipped if either required property is missing. The popover still opens, but CSS alone will not attach it to the trigger there. For a simple menu, add a measured-position fallback; for collision handling, nested menus, and focus management, keep a tested interaction library until the replacement meets your requirements.
Check the bottom and right viewport edges, zoom, scroll containers, and keyboard focus before shipping. Positioning is not the same thing as accessible menu behavior.
Try the complete anchor-positioning example below. Open the Actions menu, scroll the preview, and edit styles.css. In browsers without anchor positioning, the demo measures the trigger in JavaScript to keep the popover nearby.
Try CSS anchor positioning
Edit the CSS, open the Actions menu in the preview, and scroll to see whether it stays with its trigger.
For browser compatibility and the full specification, see the primary references in Sources below.
Sources
Why work with us
Why Tevpro?
Whether you’re a startup with a bold product idea or an established company seeking a stronger delivery partner, Tevpro delivers results. Our expert consultants specialize in building secure, scalable applications that simplify operations and drive real ROI.
FAQ
Frequently asked questions
No. It only places an element relative to an anchor. In the example, popovertarget and the Popover API handle opening, closing, and Escape.


