
CSS Anchor Positioning: Replacing Floating UI
Tooltips and dropdowns positioned by the engine, not a library — the full anchor positioning model, position-try collision fallbacks, and the middleware migration map.
TL;DR: CSS anchor positioning moves the positioning half of overlay libraries such as Floating UI — tether math, collision detection, flip-and-shift recomputation — into the engine's layout pass. As of November 2026 the core of the specification runs in all three engines (Chrome 125+, Firefox 147+, Safari 26+), although web-features still rates the feature as a whole Limited availability. That core is one of the cohort's most recent cross-engine arrivals and a realistic Floating UI replacement behind a fallback. This article covers the full positioning model — anchor(), position-area, anchor-size(), and position-try — and maps the migration middleware by middleware.
What anchor positioning replaces — and what it does not
Tooltip, dropdown, and menu libraries solve the same geometry problem: keep a floating element attached to a trigger while the page scrolls, resizes, and runs out of viewport. Solving it in JavaScript means reading bounding rectangles, computing an offset, checking for collisions, and re-running all of it on every scroll and resize event — which is why libraries like Floating UI exist, and why they ship middleware named offset, flip, shift, size, and hide.
Anchor positioning replaces that layer, and only that layer. The positioned element declares which element it is anchored to and where it wants to sit; the engine resolves the position during layout, keeps it attached to the anchor, and applies your declared fallbacks when the preferred placement would clip. No observers, no event listeners, no positioning code shipped to the client. On scroll, the spec moves the element with its default anchor (normally the one named by position-anchor) as purely a shift in position that requires no new layout, so browsers can perform that movement on their scrolling thread; anchors in other scrolling contexts use scroll offsets remembered at recalculation points, such as when the element is first displayed or changes fallbacks.
What it does not replace is overlay semantics. Whether the floating element traps focus, how it dismisses, and how it reaches the top layer are questions for the native dialog and popover machinery, which has its own dedicated coverage. This article is the geometry.
The core model: naming and binding anchors
Two properties create the relationship. The trigger declares an anchor name; the floating element binds to it and positions itself with anchor() functions in its inset properties.
.filter-button {
anchor-name: --filter;
}
.filter-menu {
position: fixed;
position-anchor: --filter;
top: anchor(bottom);
left: anchor(left);
}The floating element must be absolutely or fixed positioned — anchor positioning is an extension of positioned layout, not a new layout mode. Each anchor() call reads one edge of the anchor into the coordinate space the floating element already uses, so top: anchor(bottom) places the menu's top edge at the button's bottom edge. Add margin-top: 8px and you have reproduced the offset middleware in one declaration.
Anchor names do not need to be unique: when several elements visible to a positioned element share a name, it anchors to the nearest ancestor with that name, or else the last one in DOM order, and the anchor-scope property can limit where a name is visible. A single positioned element can even read from multiple named anchors in different inset properties, which covers the rare pattern — a range slider's tooltip spanning two handles — that used to require genuinely unpleasant JavaScript.
position-area: the placement grid
Raw anchor() functions are the low-level tool. Most placements are better expressed with position-area, which treats the anchor as the center cell of a 3×3 grid and places the floating element in one or more of the surrounding cells.
.filter-menu {
position-anchor: --filter;
position-area: block-end span-inline-end;
}That single declaration means "below the anchor, aligned to its start edge and allowed to span toward the end" — the placement JS libraries such as Floating UI spell as bottom-start. The vocabulary includes flow-relative keywords alongside physical ones: block-end and inline-start resolve against the writing mode of the containing block, so they follow right-to-left interfaces and vertical writing modes.
The practical division of labor: position-area for the standard placements that used to be a library's placement enum, anchor() functions when you need arithmetic — a menu offset by a specific distance, a caret positioned at a fraction of the anchor's width.
Sizing against the anchor
Dropdowns have a second geometric dependency on their trigger: width. anchor-size() reads the anchor's dimensions in the floating element's sizing, inset, and margin properties.
.filter-menu {
min-width: anchor-size(width);
max-height: min(24rem, 50vh);
overflow-y: auto;
}This is the match-the-trigger pattern — one of the size middleware's documented uses — plus a growth constraint so a long option list scrolls instead of overflowing the viewport. anchor-size() participates in calc(), so proportional sizing (width: calc(anchor-size(width) * 2)) works where a design calls for it.
The related visibility control is position-visibility: position-visibility: anchors-visible hides the floating element when its anchor scrolls out of view — the hide middleware, as one declaration. A tooltip attached to a table row stops hovering over unrelated content when the row leaves the scrollport.
Collision handling with position-try
Collision handling is where JavaScript positioning earned its keep, and it is where the mental-model shift is largest. In a library, flipping is code that runs on events. In CSS, fallbacks are declared states the engine chooses among during layout.
.filter-menu {
position-area: block-end;
position-try-fallbacks: flip-block, --beside;
position-try-order: most-height;
}
@position-try --beside {
position-area: inline-end;
max-height: 80vh;
}The flip-block keyword reproduces the flip middleware: if the menu does not fit below, try above. The custom @position-try block goes further than a flip ever could — a fallback can change its placement, sizing, and margins together, so "beside the trigger, taller" is one named state rather than a special case in event-handler code. position-try-order tells the engine to prefer whichever candidate yields the most height — the space-aware auto-placement that libraries compute manually.
The engine re-evaluates the chosen fallback as the user scrolls, with no code running in the page. Once this clicks, the library's positioning middleware starts to look like what it always was: an event-driven simulation of layout the engine can now do natively.
Migration and degradation
The migration path is concrete because the middleware mapping is nearly one-to-one.
| Floating UI middleware | Anchor positioning equivalent |
|---|---|
| offset | margin on the positioned element, or anchor() arithmetic |
| flip | position-try-fallbacks with flip-block / flip-inline |
| shift | position-area's default alignment, which shifts an overflowing box back inside its original containing block when it still fits there |
| size | anchor-size() with min() / max() growth limits |
| hide | position-visibility: anchors-visible |
| autoPlacement | position-try-order: most-height / most-width |
As of November 2026 the specification defines no arrow or caret feature, so arrow middleware's dynamic caret placement along the edge has no dedicated counterpart (a static caret is easy; one that slides with the flip may still need a little script). Neither does any positioning logic that depends on application state. Those are the re-own-or-descope items in this migration's parity checklist.
Support first, per the gate discipline: the core of anchor positioning works in Chrome and Edge 125+, Safari 26+, and Firefox 147+, with position-area arriving in Chrome 129, position-visibility in Safari 26.2, and position-try-order in Firefox 148 (as of November 2026, per MDN browser-compat-data). web-features still rates anchor positioning as a whole Limited availability, with only Safari 27 implementing the full feature set. Until Chrome and Edge 144 and Firefox 148, position-area values written as a single keyword such as block-end, or combined with span-all, could let the anchored box overflow the viewport; browser-compat-data records those versions as partial implementations. The core reached all three engines only in January 2026, so a real share of traffic still runs pre-arrival browsers. Verify current numbers against MDN or Baseline before deciding; this paragraph ages.
That state means adopt-with-fallback, and the gate is one feature query:
.filter-menu {
/* fallback: static position — below the trigger when the menu follows it in the DOM */
position: fixed;
inset: auto;
}
@supports (position-area: block-end) and (position-try-fallbacks: flip-block) {
.filter-menu {
position-anchor: --filter;
position-area: block-end;
position-try-fallbacks: flip-block;
}
}Two fallback strategies are defensible. For components where a fixed placement is acceptable — a menu that always opens below, clipping be damned — plain static CSS is the fallback, and the JS library is deleted outright. For components where collision handling is essential on every browser, keep the library as the fallback path during the transition, or evaluate the OddBird polyfill — counting it honestly as a dependency with its own weight, which partially defers the deletion this migration exists to achieve. Either way, run one mechanism per browser: where the primitive is supported, the JS positioning path should be fully off.