CSS Anchor Positioning lets a positioned element attach itself to another element, then react to flipping, scrolling, zoom, and available space. Below is one working demo pattern covering a tooltip and a popover dropdown, plus the syntax details and fallbacks I use in production CSS.

Basic concepts and demo markup
The element being attached to is the anchor element. The floating tooltip or menu is the positioned element. The positioned element must have a positioning scheme such as position: absolute or position: fixed. A normal static element ignores anchor inset values.
Use anchor-name on the target and position-anchor on the floater, or use the HTML popovertarget relationship. A key rule: anchor() may only be used on an inset property on the matching physical or logical axis. For example, anchor(--x center) belongs in left/right/inset-inline-start, not top.
<div class="playground">
<div class="row">
<button class="tip-trigger" aria-describedby="tip">Hover or focus me</button>
<span id="tip" class="tip" role="tooltip">Saved with CSS anchor positioning</span>
</div>
<div class="row">
<button id="menu-btn" popovertarget="menu" popovertargetaction="toggle">Options</button>
<div id="menu" class="menu" popover="auto" anchor="menu-btn">
<button type="button">Rename</button>
<button type="button">Duplicate</button>
<button type="button">Archive</button>
</div>
</div>
</div>
Core positioning rules
startandendare logical directions. In left-to-right layouts,startis left; in right-to-left layouts, it is right.- If you do not set
position-anchor, the browser can resolve a default anchor from an invoking popover target relationship. Do not rely on that for tooltips. anchor(--name 50%)selects a point on the anchor;calc(anchor(...) + 8px)adds spacing.position-areais usually simpler than manually setting every inset.

Build the tooltip
This tooltip stays centered above its trigger. It appears on hover and keyboard focus, with a short delay implemented in CSS. The delay is not a full accessible replacement for careful focus management, but it prevents flicker when a pointer crosses the gap.
.tip-trigger {
anchor-name: --tip-button;
}
.tip {
position: fixed;
position-anchor: --tip-button;
position-area: top center;
margin-bottom: 8px;
width: max-content;
max-width: 240px;
padding: 8px 10px;
border-radius: 8px;
background: #1f2937;
color: white;
opacity: 0;
pointer-events: none;
transition: opacity 120ms ease 180ms;
}
.tip-trigger:hover + .tip,
.tip-trigger:focus-visible + .tip {
opacity: 1;
}
If you prefer explicit insets, the equivalent center alignment looks like this:
.tip {
top: anchor(--tip-button bottom);
left: anchor(--tip-button center);
translate: -50% calc(-100% - 8px);
}
Common mistake: placing anchor(--tip-button center) in top. That mixes an x-axis anchor position with a y-axis inset and will not give you centered alignment.
Build the popover dropdown
Native popover gives you useful behavior for free: the browser can open and close it, light-dismiss it, place it in the top layer, and close it with Esc. It is excellent for non-modal action panels.
#menu-btn {
anchor-name: --menu-button;
}
.menu {
position: fixed;
position-anchor: --menu-button;
position-area: bottom span-inline-end;
margin-top: 8px;
width: 180px;
padding: 6px;
border: 1px solid #d1d5db;
border-radius: 10px;
background: white;
box-shadow: 0 12px 30px rgb(0 0 0 / 14%);
}
.menu button {
display: block;
width: 100%;
text-align: start;
padding: 8px 10px;
border: 0;
border-radius: 6px;
background: transparent;
}
.menu button:hover,
.menu button:focus-visible {
background: #f3f4f6;
}
For a real menu with arrow-key roving tabindex, WAI-ARIA menuitem semantics, typeahead, and exact open/close rules, you still need JavaScript. Native popover is a disclosure-like surface, not a complete ARIA menu implementation.
Positioning strategies
| Feature | Purpose | Pros | Watch outs | Support |
|---|---|---|---|---|
anchor() | Compute one inset from an anchor point | Very precise; works with calc and custom alignment | Axis must match inset; verbose for full placement | Chrome/Edge 125, Safari 26; Firefox behind flag/ongoing work |
position-area | Place an element in an area around the anchor | Compact; logical directions; easy alignment | Less granular than manual insets | Same modern anchor-supporting engines |
position-try/fallbacks | Try alternate placements when space is insufficient | Handles edges, scrolling containers, small viewports | Syntax changed during standardization | Use feature tests; older Chrome used fallback syntax |
Use position-area: bottom center for simple centered bubbles. Use explicit anchor() insets when you need offsets, pointer arrows, or unusual alignment. Use fallback rules near viewport edges.
Overflow, flipping, and the completed fallback section
Earlier drafts used @position-fallback and position-fallback. The current CSS Anchor Positioning direction uses named @position-try rules plus position-try-options, commonly written as the position-try shorthand in newer implementations. Ship all syntaxes you need and feature-test rather than assuming one version.
Current position-try example
@position-try --flip-up {
position-area: top center;
margin-top: 0;
margin-bottom: 8px;
}
@position-try --shift-inward {
position-area: bottom center;
justify-self: anchor-center;
max-width: 160px;
}
.menu,
.tip {
position-area: bottom center;
position-try-options: --flip-up, --shift-inward;
}
@supports (position-try: --flip-up) {
.menu,
.tip {
position-try: --flip-up, --shift-inward;
}
}
Older Chromium fallback syntax
@position-fallback --flip-menu {
@try {
bottom: anchor(top);
left: anchor(center);
translate: -50%;
}
@try {
top: anchor(bottom);
right: anchor(right);
}
}
.legacy-anchored {
position: absolute;
position-fallback: --flip-menu;
}
If no placement fits, a final fallback can hide or compact the component:
@position-try --compact {
position-area: bottom center;
max-width: 120px;
}
@supports not ((anchor-name: --a) and (position-try: --compact)) {
.menu,
.tip {
/* JavaScript-managed floating-ui or fixed panel styles here */
}
}
Scrolling and browser zoom are handled by the browser when the floater is connected to the anchor. Test inside a short overflow: auto container and at 200% zoom. Avoid overflow: hidden ancestors if you use position: absolute; prefer position: fixed for viewport-level popovers.
Accessibility patterns
- Use
aria-describedbyfor plain tooltip text. - Keep tooltip text reachable on keyboard focus, not only hover.
- Do not put interactive controls inside a tooltip; use a popover or dialog instead.
- Touch devices often do not expose hover reliably. On touch, show the help text inline, on tap, or use a toggle button.
- Use Esc support from native
popover="auto". Tooltips opened only by CSS hover do not get that behavior. - Never move focus away while a popover opens unless your component intentionally implements focus management.
If you need a WAI-ARIA menu, add JavaScript for role="menu", role="menuitem", roving tabindex, ArrowUp/ArrowDown/Home/End, and return-focus on close. A popover containing ordinary buttons is simpler and often the better semantic choice.
Browser support and downgrade strategy
Anchor positioning is available in Chromium 125+ and Safari 26. Firefox support has been in active development behind a flag; verify current release notes before enabling it for every Firefox user. Because syntax and support differ, gate enhanced styles with @supports or JavaScript feature detection.
if (window.CSS && CSS.supports) {
const supportsAnchor =
CSS.supports('anchor-name: --a') &&
CSS.supports('position-anchor: --a') &&
CSS.supports('top: anchor(--a bottom)');
document.documentElement.classList.toggle(
'anchors',
supportsAnchor
);
}
/* Default, broadly supported fallback */
.menu {
position: absolute;
}
:root.anchors .menu {
position: fixed;
position-anchor: --menu-button;
position-area: bottom span-inline-end;
}
For unsupported browsers, keep a simple CSS hover/focus style or load a small positioning script only when the feature test fails. This gives you progressive enhancement first, while reserving JavaScript for browsers and complex menu semantics that actually need it.