Why anchor positioning still needs a fallback
CSS anchor positioning is attractive for tooltips and bubble menus: the popup can be placed relative to a trigger without a wrapper measuring pass. But support and behavior vary, and some older browsers simply ignore the anchor-related declarations. The safer pattern is progressive enhancement: make the component usable first, enhance with anchor() and position-try rules where supported, and keep a compact JavaScript fallback for the rest.

This guide avoids assuming one CSS property is enough. We use a feature query that directly tests the functional syntax:
@supports (top: anchor(bottom))
That checks whether the browser accepts the anchor positioning function. You may also see checks for anchor-name and position-anchor. Those properties are part of the newer model, but do not infer support from a guessed value or from one property alone. If you need the named-anchor path, test the actual declarations you use, and test the interactive result in your target browsers.

The base markup
The example below works as a hover/focus tooltip. It also includes a text button inside the bubble, which makes it suitable for a small menu.
<span class="tip-host">
<button type="button" class="tip-trigger" aria-describedby="save-tip">
Save
</button>
<span class="tip-bubble" id="save-tip" role="tooltip">
Saves this draft. <a href="#help">Learn more</a>
</span>
</span>
Do not place interactive content inside title or a hover-only element. Keyboard users need focus, and touch users need a predictable tap target.
Step 1: Baseline CSS that old browsers understand
The baseline uses ordinary absolute positioning. It is simple, but it can be clipped by overflow: hidden, transformed ancestors, or containing blocks. That is an accepted limitation; the JavaScript fallback later improves placement where needed.
.tip-host {
position: relative;
display: inline-block;
}
.tip-bubble {
position: absolute;
left: 50%;
bottom: calc(100% + 8px);
transform: translateX(-50%);
min-width: 180px;
padding: 10px 12px;
border-radius: 8px;
background: #1f2937;
color: white;
opacity: 0;
visibility: hidden;
pointer-events: none;
transition: opacity 120ms ease;
z-index: 10;
}
.tip-host.is-open .tip-bubble {
opacity: 1;
visibility: visible;
pointer-events: auto;
}
Step 2: Enhance with anchor positioning and position fallbacks
In supporting browsers, the trigger becomes the anchor. The bubble is taken out of the absolute flow and positioned against that anchor. The following example uses both direct anchoring and a position-try order. Older browsers ignore the at-rule and declarations they do not understand, so the baseline remains intact.
@supports (top: anchor(bottom)) {
.tip-host:has(.is-open) .tip-bubble,
.tip-host.is-open .tip-bubble {
position: fixed;
position-anchor: --save-button;
top: anchor(bottom);
left: anchor(center);
margin-top: 8px;
margin-bottom: 0;
bottom: auto;
transform: translateX(-50%);
position-try-fallbacks: flip-block, flip-inline, --top, --bottom;
}
.tip-trigger {
anchor-name: --save-button;
}
@position-try --top {
top: auto;
bottom: anchor(top);
margin: 0 0 8px;
}
@position-try --bottom {
top: anchor(bottom);
bottom: auto;
margin: 8px 0 0;
}
}
/* Optional explicit order if your browser version supports the property
but not the shorthand spelling you are using. */
@supports (top: anchor(bottom)) {
.tip-bubble {
position-try-order: most-height;
}
}
The fallback names communicate intent clearly: try the starting side, flip across the block axis, flip across the inline axis, then use named top and bottom options. Because writing directions can affect block and inline axes, test with your actual content rather than assuming block always means vertical. Also check current browser support for @position-try, position-try-fallbacks, and position-try-order; unsupported rules are skipped rather than throwing an error.
Step 3: A complete JavaScript fallback
The fallback uses position: fixed and viewport math. It can escape some clipping contexts that absolute positioning cannot, but it is not magic: transformed ancestors, shadow roots, iframes, and nested scroll containers still need testing.
<script>
(() => {
const host = document.querySelector('.tip-host');
const trigger = host.querySelector('.tip-trigger');
const bubble = host.querySelector('.tip-bubble');
const gap = 8;
const supportsAnchor = CSS.supports('top', 'anchor(bottom)');
let open = false;
let rafId = 0;
function place() {
if (!open) return;
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(() => {
const t = trigger.getBoundingClientRect();
const b = bubble.getBoundingClientRect();
const vw = document.documentElement.clientWidth;
const vh = document.documentElement.clientHeight;
let top = t.top - b.height - gap;
if (top < gap) top = t.bottom + gap; // simple flip
if (top + b.height > vh - gap) top = Math.max(gap, vh - b.height - gap);
let left = t.left + t.width / 2 - b.width / 2;
left = Math.max(gap, Math.min(left, vw - b.width - gap));
bubble.style.position = 'fixed';
bubble.style.top = `${top}px`;
bubble.style.left = `${left}px`;
bubble.style.bottom = 'auto';
bubble.style.transform = 'none';
});
}
function show() {
open = true;
host.classList.add('is-open');
if (!supportsAnchor) place();
}
function hide() {
open = false;
host.classList.remove('is-open');
cancelAnimationFrame(rafId);
bubble.removeAttribute('style');
}
host.addEventListener('pointerenter', show);
host.addEventListener('pointerleave', hide);
trigger.addEventListener('focus', show);
trigger.addEventListener('blur', hide);
trigger.addEventListener('click', () => {
open ? hide() : show();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape') hide();
});
window.addEventListener('resize', place, { passive: true });
window.addEventListener('scroll', place, { passive: true, capture: true });
document.addEventListener('visibilitychange', () => {
if (document.hidden) hide();
});
})();
</script>
The important cleanup detail is bubble.removeAttribute('style') on close. Otherwise, old coordinates survive and the tooltip appears in the wrong place after scrolling or layout changes. The scroll listener uses capture because the trigger may sit inside a nested scroll container; passive listeners avoid blocking scroll.
Touch behavior needs a deliberate choice
Hover is unreliable on touch screens. A tap can trigger focus, then a second tap may activate the button. For a plain tooltip, showing on focus and dismissing on outside tap is usually enough. For a menu, prefer aria-expanded, click/tap toggling, focus trapping, Escape, and outside-press dismissal. Do not make essential information available only on hover.