Position a tooltip with CSS anchor positioning
Tie a tooltip to its button with anchor-name and position-area, then let position-try-fallbacks flip it below when there is no room above.
Position a hint above the Save button and let it flip underneath when that space runs out. CSS anchor positioning lets the browser use the button’s position for both placements.
Name the anchor, then place the tooltip
The button and the tooltip sit next to each other in the markup. aria-describedby associates the hint with the button as its accessible description.
<button class="save" aria-describedby="save-tip">Save</button>
<span class="tip" id="save-tip" role="tooltip">Saves a draft, publishes nothing</span>The CSS ties them together.
.save {
anchor-name: --save;
}
.tip {
position: fixed;
position-anchor: --save;
position-area: top;
margin-block: 8px;
position-try-fallbacks: flip-block;
visibility: hidden;
}
.save:hover + .tip,
.save:focus-visible + .tip {
visibility: visible;
}Hover the button, or Tab to it, and the tooltip appears 8 px above it, centred over it.
anchor-name gives the button a name that starts with two dashes, like a custom property. position-anchor tells the tooltip which named element to follow.
position-area places the tooltip on a 3×3 grid whose centre cell is the button. top expands to top span-all. The tooltip centres itself over the button in that row.
Flip it below near the top edge
To reproduce the flip, put the button about 200 px down a page tall enough to scroll. Tab to the button, then scroll until its top sits about 20 px from the viewport edge. With the default font on this test page, the hint and its 8 px gap no longer fit above.
diagram
position-area: top, with a flip-block fallback
position-try-fallbacks: flip-block tries the bottom row and preserves the 8 px gap. If the fallback also overflows, the browser keeps the original placement.
Why it stays above with position: absolute
Change the tooltip to position: absolute and repeat the scroll test. In this layout the tooltip stays above the button, where scrolling can cut it off.
In this page the absolute tooltip fits inside the initial containing block even when it moves off-screen. The fixed tooltip checks against the viewport here. An ancestor with a transform can change the containing block even for a fixed element.
Where it runs
Chrome and Edge shipped anchor positioning in version 125. The names used here, position-area and position-try-fallbacks, arrived in Chrome 129 after the working group renamed inset-area and position-try-options. Safari 26 added anchor positioning in September 2025. Use Safari 26.1 or later for the scroll test, which relies on fallbacks updating on scroll. Firefox 147 enabled anchor positioning in January 2026.
A tutorial from mid 2024 may still show the old names. The fixed tooltip can still appear near the button’s static position when those declarations are ignored. Test both edges to check that the hint is actually anchored and can flip. Let people move the pointer onto a production tooltip and dismiss it with Escape.