Educational guide to CSS Anchor Positioning
Position one box relative to another
Link the two boxes, choose what to measure, and decide what happens when space runs out. Try each technique with a recipe that keeps a usable base.
Mental model
anchor-name: --triggerposition: absoluteposition-anchor: --triggerNames start with -- and are case-sensitive. anchor-name accepts a comma-separated list. position-anchor selects one name. none removes the default anchor and auto looks for an implicit association. In the current draft, normal behaves like auto when an area is active and like none when position-area is none.
Placement areas and anchor scope
The four edges of A and the containing block divide the space into three rows and three columns. top takes the top row and top left selects its left corner. span-* covers the center track and the named track. span-all covers all three tracks on an axis.
leftinline-start | center | rightinline-end | |
|---|---|---|---|
topblock-start | 1 | ||
center | A | ||
bottomblock-end | 2 | ||
top left. One cell in the upper-left corner.2 · block-end span-inline-end. Two cells in the bottom row. The dashed line marks the boundary between them.Physical values keep their side. Logical values follow the containing block’s direction and writing mode, and self-* uses the panel’s axes. Compare the logical area in LTR, RTL, and vertical writing in the playground. Keep both values in the same family when using directional keywords.
When two sibling cards share a name and a containing block, the panel can resolve to the last acceptable anchor. Apply anchor-scope to each card to restrict lookup for those names to the card. You can scope one name, a list, or all. none leaves the name unscoped.
A logical region below the anchor
The same name in two cards
Unscoped
Scoped to each card
Insets with anchor()
anchor() calculates the distance from the edge identified by the inset to a point on the anchor. Use the default anchor or name one inside the function. With two anchors, each axis can measure a different reference.
left 0%center 50%right 100%left: anchor(50%)Horizontal LTR diagram. The left edge of panel P lines up with the midpoint of anchor A. The dashed line connects them.Use left or right anchor sides in horizontal insets and top or bottom in vertical insets. Logical insets change axis with the panel’s writing mode. start and end follow the containing block’s axes. self-start and self-end follow the panel’s axes. inside uses the side corresponding to the inset and outside uses the opposite side. center equals 50%.
If a name is missing or the side is on the wrong axis, the engine can accept the declaration and use the function’s fallback value. In this recipe, anchor(bottom, 3rem) supplies 3 rem when the reference fails and calc() adds the same offset. With no fallback, the declaration becomes invalid at computed-value time. A function fallback accepts a length or a percentage.
Measure two edges and add an offset
Size and alignment
anchor-size() returns an anchor dimension. width and height are physical, inline and block follow the containing block, and self-inline and self-block follow the panel. In the second example, justify-self: anchor-center centers the panel on the inline axis. align-self: anchor-center does the same on the block axis when the inset leaves room for alignment.
Match the width with anchor-size()
Align the centers with anchor-center
Fallback positions and visibility
When the initial position overflows, the browser can try an area such as top, a tactic such as flip-block or flip-inline, or a named rule. Combine tactics within one option using spaces and separate options with commas. flip-x and flip-y act on physical axes and have separate version requirements.
In a fresh scene, position-try-order: normal tries the list in order. Swap --above and top to compare the resulting width. The position-try shorthand also accepts the order. Omitting it restores normal. Values such as most-height prioritize the option with the most space on that axis. In the November 21 test, with both positions fitting, Chrome 158 and Firefox 159 chose the upper one and WebKit 27.2 kept the lower one.
As the geometry changes, the browser prioritizes the last successful option for as long as it still fits. If no option fits in a fresh scene, the base position can overflow. Move the anchor to observe persistence and use a preset to restore the starting point.
In the visibility preset, always keeps the panel visible. no-overflow hides it if it still overflows its inset-adjusted containing block after all the tries. Use it for nonessential content. The recent values anchor-valid and anchor-visible check whether the default anchor resolves and is visible, respectively. Earlier implementations use the plural forms.
The test using position-area hid the overflowing panel in all three engines. The same check with anchor() insets produced a different result in WebKit 27.2. Check the effect with the placement technique you use.
Change the side and size with @position-try
Popover next to its button
popovertarget connects the button and popover for declarative opening. In engines that implement the implicit association, the same button can be the anchor with position-anchor: auto. This recipe uses the explicit name --guide-trigger. The guard keeps inset: auto and margin: 0 inside the enhancement, so the popover stays centered when only the HTML API is available.
A note that flips if it runs out of room
The range thumb as an anchor
The input event updates the output value with keyboard or pointer input. Each thumb pseudo-element goes in its own rule. The recipe checks whether the inset resolves the anchor before keeping the enhancement. If the thumb cannot act as an anchor, the updated value stays in flow below the control.
The -1px in left: anchor(center, -1px) signals that the thumb did not resolve inside the container. The script reads the inset once. CSS then follows the thumb while JavaScript updates the number. With JavaScript disabled, the initial value remains visible.
On November 23, 2026, the indicator followed the thumb in Chrome 158 and Playwright WebKit 27.2. Playwright Firefox 159 accepted the ::-moz-range-thumb selector and kept the value in flow.
Display the value of a range from 0 to 100
Common pitfalls
Check the name, axis, and measured result before changing the recipe.
The panel does not follow the anchor
- Expected result
- The panel uses the box identified by anchor-name.
- Cause
- The name does not match exactly, the anchor has no acceptable box, or the panel is still in flow.
- Solution
- Check the full name, place the anchor before the panel for sibling boxes, and apply absolute or fixed to the panel.
An inset uses its fallback value
- Expected result
- The inset measures the chosen point on the axis it controls.
- Cause
- A vertical side such as bottom cannot resolve from left.
- Solution
- Change the side or inset and keep an explicit fallback to test the missing-reference case.
The list does not move the panel
- Expected result
- An option that fits is applied when the current position fails.
- Cause
- The named rule may be missing, the current position may fit, or all options may overflow.
- Solution
- Check for overflow and compare the side and size in a fresh scene.
Support and compatibility
The aggregate Web Platform DX entry has limited availability. Each row shows a Baseline status when data is available for that capability and the first documented version for each browser. Several properties in the table already work in Firefox while the aggregate entry is still pending.
Scroll the table horizontally to see all browsers.
| Capability | Baseline | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|---|
anchor-name | Newly available · Baseline 2026 | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
position-anchor: --name | No separate Baseline status | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
anchor() | Newly available · Baseline 2026 | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
position-area | Newly available · Baseline 2026 | Chrome: desktop since 129, Android since 129 | Edge: desktop since 129 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
anchor-scope | Newly available · Baseline 2026 | Chrome: desktop since 131, Android since 131 | Edge: desktop since 131 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
anchor-size() | Newly available · Baseline 2026 | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
justify-self: anchor-center | Newly available · Baseline 2026 | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
@position-try | Newly available · Baseline 2026 | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
position-try-fallbacks | Newly available · Baseline 2026 | Chrome: desktop since 128, Android since 128 | Edge: desktop since 128 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
position-try-order | Newly available · Baseline 2026 | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 148, Android since 148 | Safari: desktop since 26, iOS since 26 |
flip-block / flip-inline | Newly available · Baseline 2026 | Chrome: desktop since 128, Android since 128 | Edge: desktop since 128 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
flip-x / flip-y | Newly available · Baseline 2026 | Chrome: desktop since 144, Android since 144 | Edge: desktop since 144 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26.2, iOS since 26.2 |
position-visibility: no-overflow | Newly available · Baseline 2026 | Chrome: desktop since 125, Android since 125 | Edge: desktop since 125 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26.2, iOS since 26.2 |
anchor-valid / anchor-visible | Limited availability | Chrome: desktop since 157, Android since 157 | Edge: desktop since 157 | Firefox: Preview | Safari: desktop since 27, iOS since 27 |
position-anchor: normal | Newly available · Baseline 2026 | Chrome: desktop since 151, Android since 151 | Edge: desktop since 151 | Firefox: desktop since 151, Android since 151 | Safari: desktop since 27, iOS since 27 |
popovertarget → position-anchor: auto | Newly available · Baseline 2026 | Chrome: desktop since 133, Android since 133 | Edge: desktop since 133 | Firefox: desktop since 147, Android since 147 | Safari: desktop since 26, iOS since 26 |
Anchor positioning transforms | Limited availability | Chrome: desktop since 144, Android since 144 | Edge: desktop since 144 | Firefox: No support | Safari: desktop since 27, iOS since 27 |
@container anchored(fallback: …) | Limited availability | Chrome: desktop since 143, Android since 143 | Edge: desktop since 143 | Firefox: No support | Safari: No support |
@supports checks the declaration. Measure positions and sizes to check the rendered result, and use a separate style to verify that a conditional block applies. For example, the viewport-edge behavior of single-keyword block-end was fixed in Chrome 144 and Firefox 148, after the property itself landed.
position-anchor: match-parent appears in the draft definition to reuse the parent’s default anchor. The engines tested on November 21 rejected the value. Transform tracking has its own support entry. Verify it by measuring the panel before and after transforming the anchor.
Check anchor transform tracking
In older recipes, replace inset-area with position-area and position-try-options with position-try-fallbacks. For position-fallback, @position-fallback, and @try blocks, rewrite each alternative as an area, tactic, or named @position-try rule. Replace the former auto side of anchor() with the side you want to measure.