Anchor Positioning: Tooltips, Dropdowns, and Popovers Without JavaScript Libraries
Build tooltips, dropdowns and popovers with CSS anchor positioning and the Popover API: position-area, fallbacks, accessibility and browser support.
anchor-name, point a positioned element at it with position-anchor, and place it with position-area or the anchor() function. Fallbacks such as position-try-fallbacks: flip-block keep it on screen. Combined with the Popover API, which handles the top layer, light dismiss and keyboard behavior, it replaces most of what Popper and Floating UI were used for. It became available in all major browsers in January 2026 with Firefox 147, so keep a library fallback only for older browsers you must support.
A dropdown menu is a small thing to build until you try. It has to sit under its button, flip above when there is no room below, stay attached while the page scrolls, escape any parent with overflow: hidden, stack above everything else, close on outside click and on Escape, and return focus to the button. For a decade, the honest answer was a positioning library plus a few hundred lines of event handling.
CSS anchor positioning is a set of CSS properties that lets an absolutely or fixed positioned element size and position itself relative to another element, its anchor, anywhere on the page. The Popover API is an HTML feature, the popover attribute, that shows an element in the browser’s top layer with built-in light dismiss and focus handling. Chrome shipped anchor positioning in version 125 in 2024, Safari in version 26 in September 2025, and Firefox in version 147 in January 2026, which made it Baseline Newly available.
My position: for new work, anchor positioning plus popover should be the default for menus, tooltips and pickers. Reach for a JavaScript positioning library only when you need behavior CSS cannot express, or browsers you support cannot run it.
The three-line version
.menu-button {
anchor-name: --menu-button; /* 1. name the anchor (must start with --) */
}
.menu {
position: absolute;
position-anchor: --menu-button; /* 2. attach to it */
position-area: block-end span-inline-end; /* 3. place it below, aligned to the start edge */
}
That is a working dropdown position. position-area divides the space around the anchor into a three-by-three grid, with the anchor in the center cell, and places the element in the area you name. block-end is the row below the anchor. span-inline-end spans from the anchor’s column toward the inline end, so the menu’s start edge lines up with the button’s start edge and the menu can extend beyond it. Because the values are logical, the menu aligns correctly in right-to-left layouts too, as described in the logical properties guide.
position-area values you will actually use
| Value | Result | Typical use |
|---|---|---|
block-end |
Centered below the anchor | Tooltips below a button |
block-start |
Centered above the anchor | Tooltips above a field |
block-end span-inline-end |
Below, start edges aligned | Dropdown menus |
inline-end |
Centered beside, after the anchor | Submenus, side tips |
block-end inline-end |
Below and past the end corner | Badges, corner popouts |
center |
Over the anchor | Overlays the same size as the anchor |
Physical keywords such as bottom, top, left and span-right also work if you prefer them.
Fine control with anchor() and anchor-size()
When position-area is too coarse, the anchor() function returns the position of one of the anchor’s edges, for use in inset properties. anchor-size() returns one of its dimensions.
.combobox-list {
position: absolute;
position-anchor: --combobox;
top: anchor(bottom); /* my top edge at the anchor's bottom edge */
left: anchor(left); /* align left edges */
min-width: anchor-size(width); /* at least as wide as the input */
margin-block-start: 4px;
}
.tooltip {
position: absolute;
position-anchor: --help;
bottom: anchor(top);
justify-self: anchor-center; /* center on the anchor horizontally */
margin-block-end: 8px;
}
The anchor-center value is the easy way to center a tooltip over its trigger, something that used to need a translate(-50%) trick and broke whenever the tooltip resized.
Staying on screen with fallbacks
Floating UI’s best feature was flipping a popup when it would overflow the viewport. CSS now does this declaratively.
.menu {
position-area: block-end span-inline-end;
position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
}
The browser tries the original position first. If the menu would overflow its containing block, it tries each fallback in order: flipped to above the button, flipped to the other side, then both. flip-block and flip-inline mirror whatever position you set, including margins, so an 8px gap below becomes an 8px gap above.
For positions that are not simple mirrors, define a named fallback:
@position-try --beside {
position-area: inline-end;
margin-inline-start: 8px;
}
.submenu {
position-area: block-end span-inline-end;
position-try-fallbacks: --beside, flip-block;
}
Some browsers also support position-visibility: anchors-visible, which hides the positioned element when its anchor scrolls out of view. Treat it as an enhancement for now.
Pairing it with the Popover API
Anchor positioning only positions. A real menu or picker also needs to appear above everything, escape clipping parents, and close properly. The popover attribute handles all of that with no JavaScript:
<button popovertarget="account-menu" class="menu-button">Account</button>
<div id="account-menu" popover class="menu">
<a href="/profile">Profile</a>
<a href="/settings">Settings</a>
<button type="button">Sign out</button>
</div>
.menu-button { anchor-name: --account; }
.menu[popover] {
position-anchor: --account;
position-area: block-end span-inline-end;
position-try-fallbacks: flip-block;
inset: auto; /* undo the browser's default centering */
margin: 0;
margin-block-start: 6px;
}
The inset: auto and margin: 0 lines matter. Browsers style popovers with position: fixed, inset: 0 and margin: auto so they appear centered by default. If you skip the reset, your anchor positioning is fighting the default styles, and the popover stays in the middle of the screen.
Because the popover renders in the top layer, it escapes every ancestor’s overflow: hidden, transform and stacking context. That removes the clipping and z-index problems from the box model and positioning guide in one move. With the default popover="auto", you also get light dismiss: clicking outside or pressing Escape closes it, and opening another auto popover closes this one.
The newer invoker commands API, cross-browser since December 2025, generalizes the button wiring: <button commandfor="account-menu" command="toggle-popover"> does the same job and also covers dialogs with command="show-modal".
Tooltips: what CSS can and cannot do
Click-to-open menus are fully solved. Hover tooltips are close but not finished, and it is worth being honest about the gap.
A CSS-only tooltip
<button class="icon-button" aria-describedby="save-tip">
<svg aria-hidden="true">...</svg><span class="visually-hidden">Save</span>
</button>
<span id="save-tip" role="tooltip" class="tooltip">Save changes (Ctrl+S)</span>
.icon-button { anchor-name: --save; }
.tooltip {
position: absolute;
position-anchor: --save;
position-area: block-start;
position-try-fallbacks: flip-block;
margin-block-end: 6px;
opacity: 0;
pointer-events: none;
transition: opacity 120ms;
}
.icon-button:is(:hover, :focus-visible) + .tooltip {
opacity: 1;
}
This positions correctly and works for mouse and keyboard users. It has two limits. It is not in the top layer, so a parent with overflow: hidden can clip it. And it does not meet WCAG 1.4.13, Content on Hover or Focus, which requires that users can dismiss a tooltip without moving the pointer or focus, typically with Escape. Adding that takes a few lines of JavaScript.
The emerging declarative tooltip
Two newer features close the gap. popover="hint" creates a popover that does not close other open menus, which is the right behavior for a tooltip. The interestfor attribute opens a popover when the user shows interest by hovering or focusing, and makes the trigger its implicit anchor. Chromium ships both, and Firefox has shipped popover="hint", but neither is cross-browser yet. Use them as progressive enhancement over the CSS version above, or keep a small script for dismissal.
Anchors in lists
Anchor names are global. If twenty rows each set anchor-name: --row-actions, every row’s menu attaches to the same anchor, generally the last one in the document. Give each instance a unique name. Server-rendered templates can write it inline, which keeps the CSS generic:
<button style="anchor-name: --row-42" popovertarget="menu-42">...</button>
<div id="menu-42" popover class="menu" style="position-anchor: --row-42">...</div>
Chromium also supports anchor-scope, which limits an anchor name to a subtree so a reused name stays local to each row. Until it works everywhere, unique names are the portable choice.
A fallback for older browsers
Anchor positioning is newly Baseline, and some implementations still differ in edge cases, especially around fallbacks and shadow DOM. If you support browsers released before 2026, feature-detect and load a library only where needed:
if (!CSS.supports("anchor-name: --a")) {
const { computePosition, flip, offset } = await import("@floating-ui/dom");
// position the menu with Floating UI only in browsers that need it
}
Modern browsers download nothing extra. Older ones get the library. The OddBird CSS anchor positioning polyfill is another option if you would rather keep a single CSS code path.
Frequently Asked Questions
What is CSS anchor positioning?
CSS anchor positioning lets a positioned element place and size itself relative to another element, called the anchor. You name the anchor with anchor-name, attach the element with position-anchor, and position it with position-area or the anchor() function, with built-in fallbacks to keep it on screen.
Is CSS anchor positioning supported in all browsers?
Yes, since January 2026. Chrome and Edge added it in version 125, Safari in version 26, and Firefox in version 147, making it Baseline Newly available. Some advanced details still differ between engines, so test fallbacks and keep a library fallback for older browsers you support.
Can anchor positioning replace Popper or Floating UI?
For most menus, dropdowns, pickers and popovers, yes, especially when combined with the Popover API for top-layer rendering and light dismiss. Keep a library for older browsers or for behaviors CSS cannot express, such as custom collision logic based on application state.
Why does my popover stay in the center of the screen?
Browsers give popovers position: fixed, inset: 0 and margin: auto by default, which centers them. Add inset: auto and margin: 0 to the popover so anchor positioning can place it next to its anchor.
Let the browser do the tethering
Positioning libraries existed because CSS had no way to say “put this next to that”. Now it does, and the Popover API handles the stacking, clipping and dismissal that made popups hard. Build menus declaratively, keep a small script for tooltip dismissal until the newer APIs land everywhere, and feature-detect for older browsers. Color is another former JavaScript job, and I cover it in building accessible color palettes with oklch().
Rule of thumb: if a popup needs JavaScript only to stay next to its button, it needs anchor positioning instead.
Originally posted on 5 March 2026 and post last modified on 5 March 2026