How CSS Anchor Positioning Keeps a Tooltip Near Its Button
On January 13, 2026, Firefox 147 arrived with CSS anchor positioning enabled by default, according to the developer release notes on MDN Web Docs. For a tooltip, the change meant the browser could take the position of the button it describes and use that position to place the floating box. Near the edge of the visible page, the browser could try a different side of the same button, provided the stylesheet gave it an alternative.

A tooltip is a short explanation that appears near a control. The control supplies a reference box, called the anchor. Its edges give the browser places to line up the tooltip; its width and height give the browser lengths it can use to size the tooltip or set the gap between the boxes. The useful distinction is between choosing a reference, choosing what to measure from it and choosing what to do when the result is too close to an edge.
The CSS Working Group, which writes the specification, describes the layout problem in its working draft: “For example, an author might want to position a tooltip centered and above the targeted element, unless that would place the tooltip offscreen, in which case it should be below the targeted element.” The button can stay in its row of controls while the tooltip moves to the other side of it without pushing the other buttons along the row.
What information does the browser take from the button?
The browser has the box the button occupies in the current layout. It can use the top or bottom edge, the left or right edge, or a point such as the center along the relevant axis. Those positions come from the button as laid out, so they can change when a toolbar wraps or the page scrolls. The box also has dimensions the browser can use in a separate calculation.
The browser first needs to know which box to consult. In the explicit setup in MDN’s guide, the stylesheet gives the reference element a name and gives the floating element a position-anchor pointing to that same name. The floating element uses absolute or fixed positioning, which takes it out of the ordinary flow of the page. Giving it a reference prepares it to use that box. A placement declaration then tells the browser which edge or area matters.
That distinction shows up in the guide’s scrolling example. A small square serves as the reference and a separate information box sits diagonally below it. The square is in the page content. The information box uses fixed positioning, but its inset distances, the distances normally measured from the edges of its positioning space, are calculated from the square. As the page scrolls, the square and the information box move together. The browser keeps using the square’s edges as those edges move through the visible page.
- Name the reference: The stylesheet identifies the button as an anchor.
- Associate the boxes: The floating element points to the same name.
- Specify the placement: The browser uses the chosen edge or area around the anchor.
The reference can be wrong even when the placement rule is sound. MDN’s guide illustrates this with repeated sections, each containing an anchor and an orange information box. The sections reuse the same anchor name. Left unscoped, the name can resolve to the last eligible anchor in source order, the order in which the elements appear in the document. Scoping the name to each section keeps the orange box beside the anchor in its own section. In a row of repeated controls, that is the difference between a tooltip that follows the intended button and one that appears beside a button farther down the markup.
How does the tooltip use the button’s position and size?
The anchor() function translates a particular position on the button into a length the browser can use to set an inset. MDN’s guide explains that the returned length depends on the anchor’s position. To put a tooltip below a button, the upper edge of the tooltip can take its position from the button’s bottom edge. A margin leaves room between the boxes. Horizontal centering can then line the middle of the tooltip up with the middle of the button, even when the boxes have different widths.
Another approach is to give the browser an area rather than a particular pair of edges. The position-area property divides the positioning space into regions around the anchor. A stylesheet can request the area below the button and centered on it, or an area that extends farther to one side. The area moves with the button because its boundaries are defined in relation to that box. That makes the preferred position easy to describe when the design calls for a side or a corner rather than a precisely measured offset.
Size is a separate choice. The anchor-size() function supplies a dimension of the reference box, such as its width. A longer explanation can keep a width suited to its text while staying centered below a narrow button. A floating panel that needs to line up with a wide trigger can instead take a size cue from the anchor. Which behavior makes sense depends on what is inside the floating box. A narrow icon button makes a fine reference for a line of help text, but its width would give that line very little room.
The dimension can also control the space between the boxes. In the sizing guide’s margin example, the gap is a fraction of the anchor’s width. Widening the anchor widens the gap as part of the same layout. A fixed margin would keep the gap constant as the control grows. That choice is independent of a decision such as placing the box on the right or lining it up along the middle. The anchor supplies a length for the gap and a location for the alignment.
Scroll sideways to see all columns.
| Layout choice | CSS feature | Reference used |
|---|---|---|
| Place an edge | anchor() | A position on the anchor along the relevant axis |
| Choose a region | position-area | An area laid out around the anchor |
| Line up the centers | anchor-center | The center of the default anchor along the alignment axis |
| Set a dimension | anchor-size() | A length such as the anchor’s width or height |
What if the preferred position runs out of room?
The browser can try the alternatives supplied through position-try-fallbacks. The decision is about fit. The box has to fit within its allotted positioning space, which may be the visible part of the browser window or a region established by the layout. A position that works in the middle of that space can put part of the box beyond its edge once the control moves. The browser checks the new placement against that boundary.
MDN’s overflow guide shows this with a box that starts above and to the left of its anchor. When the anchor approaches the top of the window, a vertical flip puts the box beneath it, still on the left. Near the left edge, a horizontal flip puts the box on the right, still above. At the upper-left corner, either flip on its own can leave part of the box outside the window. The guide’s second version gives the browser a combined flip so the box can land below and to the right.

Scroll sideways to see all columns.
| Anchor location in the MDN demo | Placement that fits in the example |
|---|---|
| Away from the edges | Above and left of the anchor |
| Near the top | Below and left after the vertical flip |
| Near the left edge | Above and right after the horizontal flip |
| Near the upper-left corner | Below and right with the combined flip |
The punctuation in that list of fallbacks matters. As the overflow guide shows, a comma separates candidates, while a space between the two flip keywords lets the browser try both changes together. Each candidate starts from the preferred placement. So a vertical attempt followed by a horizontal attempt gives the browser two separate places to test. It takes a combined option to reach the diagonal result in that example.
A different position can also call for a different shape. The same guide shows a custom fallback that puts the information box to the left with a different width and a margin on the side nearest the anchor. A short, wide box above a control and a taller, narrower box beside it can hold the same text. The room available on each side determines whether a given combination of position and size will work.
The width from a custom fallback belongs to that placement. In the guide’s example, a narrower box can fit to the left, while a box below the anchor can use the original width. If scrolling changes which option applies, the overrides from the old option go away. Room on the new side determines how much horizontal space the explanation gets and how its lines wrap.
Floating UI, the JavaScript library formerly called Popper, approaches the same problem in script. Its flip documentation describes a placement calculation that can try the opposite side when the floating box would overflow. CSS anchor positioning puts the preferred placement and its alternatives in the stylesheet for the browser to use during layout. In either approach, the relevant comparison is between the space around the control and the space the floating element needs.
The corner in the MDN demo makes that calculation visible. At the top edge, the box has room to move down. At the left edge, it has room to move right. On a page that uses both moves together, someone reading the tooltip at the corner can still see the whole explanation beside the same control, even though the space where it first appeared has slipped beyond the window.
Frequently Asked Questions
Can a popover use CSS anchor positioning?
A button that opens an HTML popover using popovertarget creates an implicit anchor relationship with that popover. MDN’s guide to popovers shows that the default styling includes automatic margins that center the box. Clearing the default inset and margin settings lets the stylesheet place the popover relative to its invoker.
Can CSS anchor positioning match a floating panel to the width of its trigger?
A panel can set its width to anchor-size(width) for an exact match to the width supplied by the anchor. The same function can supply a minimum width instead, so the trigger sets the lower limit while the panel can grow to accommodate its contents.
What is the role of anchor-name in CSS anchor positioning?
The anchor-name property gives the reference element an identifier that begins with a pair of hyphens. Changing the reference element’s anchor-name to none removes its explicit name. Setting position-anchor to none on the floating box leaves that box without a default anchor.
Can an anchored element be hidden when its anchor scrolls out of view?
The anchors-visible setting of position-visibility can hide the floating box when its anchor is completely hidden. With no-overflow, the test is different: the browser can hide the floating element when the floating element itself overflows the available space.
Sources
- MDN Web Docs: Firefox 147 release notes for developers
- W3C CSS Working Group: CSS Anchor Positioning Module Level 1 (Working Draft)
- MDN Web Docs: Using CSS anchor positioning
- MDN Web Docs: Fallback options and conditional hiding for overflow
- MDN Web Docs: Using the Popover API
- MDN Web Docs: CSS dashed-ident type
- Floating UI: Migration
- Floating UI: flip