Tooltips, dropdowns and popovers
The Popover API with CSS anchor positioning
Features it needs
- PopoverNewly available
- Anchor positioningLimited availability
Chrome125
Edge125
Firefox147
Safari26
Two separate problems used to need a library. Putting an element in the top layer so it escapes overflow and z-index, and keeping it pinned to its trigger. The popover attribute solves the first, including light dismiss, Escape to close and focus handling, with no JavaScript at all. CSS anchor positioning solves the second, including position-try fallbacks that flip the popover when it would overflow the viewport. Anchor positioning is the part to check before you commit, because it has not reached Baseline yet.
When this applies
Building a tooltip, dropdown menu or popover anchored to a trigger.
The native approach
<button popovertarget="menu" id="trigger">Open</button>
<div popover id="menu">Anchored content</div>
<style>
#trigger {
anchor-name: --trigger;
}
#menu {
position: absolute;
position-anchor: --trigger;
/* Sit below the trigger, aligned to its left edge. */
top: anchor(bottom);
left: anchor(left);
margin-top: 0.5rem;
/* Flip above when there is no room below. */
position-try-fallbacks: flip-block;
}
</style>When the dependency is still right
An answer that always says "the platform covers it" is worse than no answer. These are the cases where this one does not hold.
- You need Baseline-level support for the positioning. Anchor positioning is in all three engines now, but only from Chrome 125, Safari 26 and Firefox 147, so anything older needs a JavaScript fallback or a static position.
- You need collision handling beyond position-try-fallbacks, such as shifting along an axis to stay in view rather than flipping.
- You need an arrow that tracks the trigger across a flip.
- A popover must stay open while a second one opens, or nest inside another. Auto popovers close their ancestors.
- You need hover-with-intent timing, which the platform does not cover.
Building it
This catalog stops at the swap. These guides go through the implementation and the fallbacks. They come from Google Chrome's modern-web-guidance, Apache-2.0.
- Position aware tooltipsui-atoms
- Interest triggered tooltipsui-behaviors
- Resilient context menus and nested dropdownsui-atoms