Anchor Positioning: Tethering Tooltips and Menus With anchor() and position-area
Positioning an element relative to another anywhere on the page: anchor-name and position-anchor, position-area placements, anchor() and anchor-size(), fallbacks with position-try, position-visibility, implicit anchors for popovers, and anchor-scope.
kvi5hnuCode Sprout team member10 min readOn this page
Tooltips, dropdown menus, popovers and labels all need to sit next to another element, their anchor. With absolute positioning (article 56), that only works if the anchor is the containing block, so the menu has to live inside the button's wrapper, and it gets clipped by any overflow on the way up. For years the fix was JavaScript that measured the button and set coordinates on scroll and resize.
Anchor positioning does it in CSS. You name an anchor, tell an absolutely or fixed positioned element to use it, and place the element relative to the anchor's edges, with automatic fallbacks when it would overflow the screen. The core is in all browsers: Chrome 125, Safari 26 and Firefox 147, Baseline since January 2026.
Naming and using an anchor
.info-button { anchor-name: --info; } /* a dashed ident, like a custom property name */
.info-tip {
position: absolute; /* or fixed */
position-anchor: --info; /* use that anchor */
position-area: block-start; /* centered above it */
}
anchor-namegives an element one or more anchor names, which are dashed idents:anchor-name: --info.position-anchorsets the default anchor for a positioned element. Onlyposition: absoluteorfixedelements can be anchored.- The anchor must be laid out before the anchored element. In practice, the anchor can't be inside the anchored element, and if the anchor is itself absolutely positioned in the same containing block, it must come earlier in the document. An ordinary in-flow anchor works wherever it is: in Chrome, an anchored element earlier in the HTML than its anchor still finds it.
The anchored element still has a containing block as usual, but its position comes from the anchor. It's often best placed at the end of <body>, or in the top layer as a popover (article 60), where no ancestor's overflow can clip it.
position-area: placing with a grid
position-area is the quickest way to place an anchored element. Imagine a 3 × 3 grid around the anchor, with the anchor in the center cell, and pick a cell or a span of cells:
top left | top center | top right
center left | (the anchor) | center right
bottom left | bottom center | bottom right
.tip { position-area: top; } /* above, centered (one keyword: the other axis is span-all) */
.menu { position-area: bottom span-right; } /* below, starting at the anchor's left edge, extending right */
.side { position-area: right; } /* to the right, vertically centered */
| Keyword type | Examples |
|---|---|
| physical | top, bottom, left, right, center |
| logical | block-start, block-end, inline-start, inline-end, start, end |
| spans | span-left, span-right, span-top, span-bottom, span-inline-end, span-all |
With position-area, the element's default alignment points it toward the anchor: position-area: top puts it directly above, centered on the anchor, without you setting any insets. The area also acts as the containing block for sizing, so width: 100% means the width of that grid area. A single keyword is short for a span across the other axis: top means top span-all, an area as wide as the whole containing block, and the default alignment is what centers the element on the anchor. Name both axes, top center, when the area should be only the anchor's column.
Tested in Chrome: with an 80px-wide anchor at x = 100, a 50px tooltip with position-area: bottom sits at x = 115, centered, and one with bottom span-right starts at x = 100, the anchor's left edge. With width: 100% in a 500px containing block, bottom gives a 500px box, and bottom center an 80px one, exactly as wide as the anchor.

Each label hugs the anchor because position-area aligns it toward the center cell; the red lines are themselves anchored with anchor().
anchor() and anchor-size(): precise placement
For full control, use the anchor() function in the inset properties. It returns the position of one of the anchor's edges:
.underline {
position: absolute;
position-anchor: --tab;
top: anchor(bottom); /* my top edge at the anchor's bottom edge */
left: anchor(left);
width: anchor-size(width); /* as wide as the anchor */
height: 3px;
}
anchor(<side>):top,bottom,left,right,start,end,center, or a percentage such asanchor(50%). It's only valid in inset properties (top,left,inset-block-start, ...).anchor(--name side)refers to a named anchor other than the default, so one element can be positioned between two anchors.- A fallback value is allowed:
anchor(bottom, 0px). anchor-size(width)(orheight,inline,block) gives the anchor's size, for sizes, margins and insets: a dropdown as wide as its button,min-width: anchor-size(width).calc()works with both:top: calc(anchor(bottom) + 0.5rem).

Both extra elements take their geometry from the anchor, so a longer tab label or button text resizes them automatically.
anchor-center is an alignment value that centers the element on the anchor along an axis, when you place it with insets instead of position-area:
.tip { position: absolute; position-anchor: --b; bottom: anchor(top); justify-self: anchor-center; }
Fallbacks with position-try
A tooltip above a button near the top of the screen would be cut off. position-try-fallbacks lists alternatives that the browser tries, in order, when the element overflows its containing block:
.menu {
position: absolute;
position-anchor: --menu-button;
position-area: bottom span-right;
position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
}
| Fallback | Means |
|---|---|
flip-block | swap block-start and block-end: below becomes above |
flip-inline | swap inline-start and inline-end: right becomes left |
flip-x, flip-y | the physical versions |
a position-area value, such as top | try that area instead |
--name | a custom @position-try rule |
A @position-try rule defines a full alternative, with its own insets, margins, sizes and alignment:
@position-try --left-of {
position-area: left;
margin-inline-end: 0.5rem;
max-inline-size: 12rem;
}
.tip { position-try-fallbacks: --left-of, flip-block; }
position-try-order can pick the fallback with the most room instead of the first that fits: position-try-order: most-height for a menu that should open wherever it can show the most items. The position-try shorthand sets both.

The second panel is the fallback at work: the browser tried top, saw the overflow, and used the first fallback that fits.
Tested in Chrome: an anchored box with position-area: bottom next to the bottom edge of the page, and position-try-fallbacks: flip-block, moves above its anchor.
Hiding with position-visibility
When the anchor scrolls out of view inside a scroll container, the anchored element can be left floating on its own. position-visibility hides it in those cases:
| Value | Hides the element when |
|---|---|
always | never hides it |
anchor-visible (the default) | the anchor is completely hidden, scrolled out or clipped |
no-overflow | the element overflows its containing block even after the fallbacks |
The spec renamed the plural anchors-visible to the singular anchor-visible. Older Chrome and Safari versions only know the plural form, which is still accepted.
Implicit anchors for popovers
A popover opened by a button with popovertarget (or commandfor) gets that button as its implicit anchor: no anchor-name or position-anchor needed. A popover opened from script with showPopover() has no invoker, so pass one, showPopover({ source: button }), or give it a position-anchor. With the top layer handling stacking and clipping (article 60), a tooltip or menu takes very little CSS:
body { font: 0.85rem system-ui, sans-serif; margin: 1rem; }
.bar { display: flex; justify-content: space-between; }
button { font: inherit; padding: 0.45rem 0.75rem; border: 1px solid #8a3b12; border-radius: 6px; background: #f4efe6; }
[popover] {
margin: 0; /* the UA style centers popovers with margin: auto */
border: 1px solid #d8cfc0; border-radius: 8px; padding: 0.6rem 0.75rem;
background: white; box-shadow: 0 6px 16px rgb(0 0 0 / 0.15);
}
#info {
position-area: bottom; /* below the button that opened it, centered */
margin-block-start: 0.4rem;
inline-size: 14rem;
}
#menu {
position-area: bottom span-right; /* below, extending to the right of the button */
min-inline-size: 10rem;
margin-block-start: 0.4rem;
position-try-fallbacks: bottom span-left; /* not enough room: extend to the left instead */
display: none;
}
#menu:popover-open { display: grid; }
#menu a { color: #2b2118; padding: 0.3rem 0.25rem; text-decoration: none; }
#menu a:hover { background: #f4efe6; }
.hint { color: #555; margin-top: 7rem; }
Popovers are position: fixed in the top layer by default, so they aren't clipped by any container. The UA's centering margin must be reset to 0 before position-area can place them. A box centered with position-area, like the info popover, is also shifted to stay inside the viewport, before any fallback is needed: next to a button near the left edge, it's pushed in rather than hanging off.
anchor-scope
Anchor names are global: if every card in a list has a button with anchor-name: --card-button, an anchored element in any card finds the last one in the page. anchor-scope limits a name to a subtree:
.card { anchor-scope: --card-button; } /* inside each card, --card-button means that card's button */
.card .more { anchor-name: --card-button; }
.card .more-menu { position: absolute; position-anchor: --card-button; position-area: bottom span-left; }
anchor-scope: all scopes every anchor name declared inside the element.
Accessibility
Anchor positioning is visual only. It doesn't tell screen readers that a tooltip belongs to its button. Keep the relationship in HTML: popovertarget creates it for popovers, and otherwise use aria-describedby for tooltips or aria-controls and aria-expanded for menus. Tooltips should be reachable with the keyboard, not only on hover.
What's current
- Core anchor positioning (
anchor-name,position-anchor,anchor(),anchor-size(),position-area,@position-try,position-try-fallbacks,anchor-center,anchor-scope): Chrome 125 to 131, Safari 26, Firefox 147; Baseline since January 2026. - Implicit anchors for popovers opened with
popovertargetorcommandfor: all three browsers. position-visibilitysingular values (anchor-visible,anchor-valid): Chrome 157 and Safari 27; Firefox only in preview. The plural forms are deprecated.- Old names, from early Chrome versions:
inset-area(nowposition-area) andposition-try-options(nowposition-try-fallbacks). Don't use them. - Anchored container queries,
container-type: anchoredwith@container anchored(fallback: ...), style an element by which fallback is active, in Chrome 143 only.
Common questions
Why doesn't my anchored element move to the anchor?
It isn't position: absolute or fixed, the anchor name doesn't match (it must start with --), or the anchor is inside the anchored element, or is an absolutely positioned element that comes after it in the same containing block.
Why is my popover in the middle of the screen instead of next to its button?
Popovers have margin: auto from the browser's styles. Set margin: 0, then use position-area or anchor().
How do I make a dropdown as wide as its button?
min-inline-size: anchor-size(inline). Or use position-area: bottom center with inline-size: 100%, since that area is exactly as wide as the anchor. Plain bottom spans the whole containing block, so 100% would be far too wide.
Several cards use the same anchor name, and every menu opens at the last card. Why?
Anchor names are global, and the last one wins. Add anchor-scope on each card.
Do I still need JavaScript for tooltips? Not for positioning. Use popovers for showing and hiding, and anchor positioning for placement.
Summary
anchor-name: --xnames an anchor;position-anchor: --xmakes an absolutely or fixed positioned element use it.position-areaplaces the element in a 3 × 3 grid around the anchor, aligned toward it.anchor()in insets andanchor-size()in sizes give precise control;anchor-centercenters on the anchor.position-try-fallbacks(flip-block,flip-inline, areas or@position-tryrules) handles overflow;position-try-orderpicks the roomiest.position-visibilityhides the element when its anchor is hidden or it overflows.- Popovers opened by a button anchor to it automatically;
anchor-scopelimits names to a subtree.
Practice questions
Write CSS that puts .tip centered above .help, with 0.5rem of space, flipping below if there's no room.
Answer
.help { anchor-name: --help; }
.tip {
position: absolute;
position-anchor: --help;
position-area: top;
margin-block-end: 0.5rem;
position-try-fallbacks: flip-block;
}
Write a 3px indicator bar under the active tab, as wide as the tab, using anchor() and anchor-size().
Answer
.tab[aria-selected="true"] { anchor-name: --active-tab; }
.indicator {
position: absolute;
position-anchor: --active-tab;
top: anchor(bottom);
left: anchor(left);
width: anchor-size(width);
height: 3px;
background: #8a3b12;
}
What does position-area: bottom span-right do?
Answer
It places the element below the anchor, starting at the anchor's left edge and extending to the right, so it lines up with the anchor's start.
A popover opened with popovertarget has position-area: bottom, but it still appears centered in the viewport. What's missing?
Answer
margin: 0. The browser's popover styles include margin: auto, which centers it in the viewport and overrides the anchor alignment.
Previous: Stacking Contexts and z-index: Why Your z-index Doesn't Work
Next: Popovers, Dialogs and the Top Layer: Styling, ::backdrop and Entry Animations

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.