Support0

CSS Anchor Positioning playground

Place a panel with position-area or anchor() and compare the fallbacks the browser tries when it runs out of room.

Ask AI

CSS Anchor Positioning playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
A
P

A · Anchor / P · Panel

The lines cross the anchor’s edges. The solid outline marks the area when one applies.

CSS feature query
Condition matchedCondition did not match. The panel stays in flow.
Panel association
Anchor with a matching nameCSS association inactive
HTML
<div class="anchor-area">
  <div class="anchor">A</div>
  <div class="panel">P</div>
</div>
CSS
.anchor-area {
  --anchor-width: 40px;
  --anchor-height: 24px;
  --anchor-x: min(104px, calc(100% - 64px));
  --anchor-y: 84px;
  direction: ltr;
  writing-mode: horizontal-tb;
  position: relative;
  inline-size: min(100%, 260px);
  block-size: 200px;
  outline: 1px solid;
}

.anchor-area > :is(.anchor, .panel) {
  display: grid;
  place-items: center;
  outline: 1px solid;
  outline-offset: -1px;
}

.anchor-area > .anchor {
  inline-size: var(--anchor-width);
  block-size: var(--anchor-height);
}

.anchor-area > .panel {
  inline-size: 64px;
  block-size: 36px;
}

@supports (anchor-name: --primary) and (position-anchor: --primary) and (position-area: top) {
  .anchor-area > .anchor {
    position: absolute;
    left: var(--anchor-x);
    top: var(--anchor-y);
    anchor-name: --primary;
  }

  .anchor-area > .panel {
    position: absolute;
    position-anchor: --primary;
    position-area: top;
  }
}

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

Anchoranchor-name: --trigger
Same name
Panelposition: absoluteposition-anchor: --trigger
Association diagram. The anchor can stay in flow. The panel uses absolute or fixed positioning and selects the same name.Once the boxes are linked, position-area selects a region, anchor() reads a point, and anchor-size() reads a dimension.

Names 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.

The position-area grid
leftinline-startcenterrightinline-end
topblock-start1
centerA
bottomblock-end2
Diagram for horizontal-tb and LTR. Each header pairs a physical reference with its logical equivalent. Anchor A occupies the center cell.1 · 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

A
P
P uses the block-end row and the region covering the center and inline-end columns.
A logical region below the anchor
<div class="anchor-guide-area">
  <div class="anchor">A</div>
  <div class="panel">P</div>
</div>
.anchor-guide-area {
  position: relative;
  min-block-size: 7rem;
}

.anchor-guide-area > :is(.anchor, .panel) {
  display: grid;
  place-items: center;
  min-block-size: 2rem;
  max-inline-size: 100%;
  outline: 1px solid;
  outline-offset: -1px;
}

.anchor-guide-area > .anchor {
  inline-size: 8rem;
}

.anchor-guide-area > .panel {
  inline-size: 4rem;
}

@supports (anchor-name: --anchor-guide-area) and (position-anchor: --anchor-guide-area) and (position-area: block-end span-inline-end) {
  .anchor-guide-area > .anchor {
    anchor-name: --anchor-guide-area;
  }

  .anchor-guide-area > .panel {
    position: absolute;
    position-anchor: --anchor-guide-area;
    position-area: block-end span-inline-end;
  }
}

The same name in two cards

Unscoped

Scoped to each card

Without scoping, P1 and P2 are positioned relative to B. Scoping --trigger links P1 to A and P2 to B. The code includes the scope on each card.
The same name in two cards
<div class="anchor-scope-example">
  <div class="scope-card">
    <div class="anchor">A</div>
    <div class="panel above">P1</div>
  </div>
  <div class="scope-card">
    <div class="anchor">B</div>
    <div class="panel below">P2</div>
  </div>
</div>
.anchor-scope-example {
  position: relative;
  inline-size: min(100%, 260px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.anchor-scope-example > .scope-card {
  display: grid;
  justify-items: center;
  align-content: center;
  min-block-size: 112px;
  gap: 8px;
  outline: 1px dashed;
}

.anchor-scope-example > .scope-card > :is(.anchor, .panel) {
  display: grid;
  place-items: center;
  inline-size: 48px;
  block-size: 24px;
  outline: 1px solid;
}

@supports (anchor-name: --trigger, --label) and (position-anchor: --trigger) and (position-area: top center) and (position-area: bottom center) {
  .anchor-scope-example > .scope-card > .anchor {
    anchor-name: --trigger, --label;
  }

  .anchor-scope-example > .scope-card > .panel {
    position: absolute;
    position-anchor: --trigger;
  }

  .anchor-scope-example > .scope-card > .above {
    position-area: top center;
  }

  .anchor-scope-example > .scope-card > .below {
    position-area: bottom center;
  }
}

@supports (anchor-scope: --trigger) {
  .anchor-scope-example > .scope-card {
    anchor-scope: --trigger;
  }
}

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%
A
P
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

A
P
The left edge of P lines up with A. Its top edge sits 0.5 rem below A.
Measure two edges and add an offset
<div class="anchor-guide-inset">
  <div class="anchor">A</div>
  <div class="panel">P</div>
</div>
.anchor-guide-inset {
  position: relative;
  min-block-size: 7rem;
}

.anchor-guide-inset > :is(.anchor, .panel) {
  display: grid;
  place-items: center;
  min-block-size: 2rem;
  max-inline-size: 100%;
  outline: 1px solid;
  outline-offset: -1px;
}

.anchor-guide-inset > .anchor {
  inline-size: 8rem;
}

.anchor-guide-inset > .panel {
  inline-size: 4rem;
}

@supports (anchor-name: --anchor-guide-inset) and (position-anchor: --anchor-guide-inset) and (top: calc(anchor(bottom, 3rem) + 0.5rem)) and (left: anchor(left, 0px)) {
  .anchor-guide-inset > .anchor {
    anchor-name: --anchor-guide-inset;
  }

  .anchor-guide-inset > .panel {
    position: absolute;
    position-anchor: --anchor-guide-inset;
    top: calc(anchor(bottom, 3rem) + 0.5rem);
    left: anchor(left, 0px);
  }
}

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()

A
P
P grows from 4 rem to 8 rem, the measured width of A in this example.
Match the width with anchor-size()
<div class="anchor-guide-size">
  <div class="anchor">A</div>
  <div class="panel">P</div>
</div>
.anchor-guide-size {
  position: relative;
  min-block-size: 7rem;
}

.anchor-guide-size > :is(.anchor, .panel) {
  display: grid;
  place-items: center;
  min-block-size: 2rem;
  max-inline-size: 100%;
  outline: 1px solid;
  outline-offset: -1px;
}

.anchor-guide-size > .anchor {
  inline-size: 8rem;
}

.anchor-guide-size > .panel {
  inline-size: 4rem;
}

@supports (anchor-name: --anchor-guide-size) and (position-anchor: --anchor-guide-size) and (top: anchor(bottom, 2rem)) and (inline-size: anchor-size(width, 4rem)) {
  .anchor-guide-size > .anchor {
    anchor-name: --anchor-guide-size;
  }

  .anchor-guide-size > .panel {
    position: absolute;
    position-anchor: --anchor-guide-size;
    inset-inline-start: 0;
    top: anchor(bottom, 2rem);
    inline-size: anchor-size(width, 4rem);
  }
}

Align the centers with anchor-center

A
P
P keeps its 4 rem width, and its horizontal center lines up with the center of A.
Align the centers with anchor-center
<div class="anchor-guide-center">
  <div class="anchor">A</div>
  <div class="panel">P</div>
</div>
.anchor-guide-center {
  position: relative;
  min-block-size: 7rem;
}

.anchor-guide-center > :is(.anchor, .panel) {
  display: grid;
  place-items: center;
  min-block-size: 2rem;
  max-inline-size: 100%;
  outline: 1px solid;
  outline-offset: -1px;
}

.anchor-guide-center > .anchor {
  inline-size: 8rem;
}

.anchor-guide-center > .panel {
  inline-size: 4rem;
}

@supports (anchor-name: --anchor-guide-center) and (position-anchor: --anchor-guide-center) and (justify-self: anchor-center) {
  .anchor-guide-center > .anchor {
    anchor-name: --anchor-guide-center;
  }

  .anchor-guide-center > .panel {
    position: absolute;
    position-anchor: --anchor-guide-center;
    inset-inline: 0;
    inset-block-end: 0;
    justify-self: 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

With A near the bottom edge, --above places P above it at 88 px wide. The top option keeps it 64 px wide.
Change the side and size with @position-try
<div class="anchor-tries">
  <div class="anchor">A</div>
  <div class="panel">P</div>
</div>
.anchor-tries {
  --anchor-x: calc(50% - 20px);
  --anchor-y: calc(100% - 26px);
  position: relative;
  inline-size: min(100%, 260px);
  block-size: 200px;
  outline: 1px solid;
}

.anchor-tries > :is(.anchor, .panel) {
  display: grid;
  place-items: center;
  outline: 1px solid;
  outline-offset: -1px;
}

.anchor-tries > .anchor {
  inline-size: 40px;
  block-size: 24px;
}

.anchor-tries > .panel {
  inline-size: 64px;
  block-size: 36px;
}

@supports (anchor-name: --primary) and (position-anchor: --primary) and (position-area: bottom) {
  .anchor-tries > .anchor {
    position: absolute;
    left: var(--anchor-x);
    top: var(--anchor-y);
    anchor-name: --primary;
  }

  .anchor-tries > .panel {
    position: absolute;
    position-anchor: --primary;
    position-area: bottom;
  }
}

@supports (anchor-name: --primary) and (position-anchor: --primary) and (position-area: bottom) and (position-try-fallbacks: --above, top) and (position-try-order: normal) {
  .anchor-tries > .panel {
    position-try-order: normal;
    position-try-fallbacks: --above, top;
  }

  @position-try --above {
    position-area: top;
    inline-size: 88px;
  }
}

@supports (anchor-name: --primary) and (position-anchor: --primary) and (position-area: bottom) and (position-visibility: always) {
  .anchor-tries > .panel {
    position-visibility: always;
  }
}

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

Open the note near the bottom of the example. With anchoring, it opens above the button. Escape closes it and returns focus to the button.
A note that flips if it runs out of room
<button type="button" popovertarget="guide-note">Open note</button>
<div id="guide-note" popover="auto">
  <p>The button opens this note in the top layer.</p>
  <button type="button" popovertarget="guide-note" popovertargetaction="hide" autofocus>
    Close note
  </button>
</div>
[popovertarget="guide-note"] {
  font: inherit;
  min-block-size: 24px;
}

#guide-note {
  box-sizing: border-box;
  max-inline-size: calc(100vi - 1rem);
  max-block-size: calc(100vb - 1rem);
  overflow: auto;
  overflow-wrap: anywhere;
}

@supports not selector(:popover-open) {
  [popovertarget="guide-note"] {
    display: none;
  }
}

@supports (anchor-name: --guide-trigger) and (position-anchor: --guide-trigger) and (position-area: block-end span-inline-end) and (position-try-fallbacks: flip-block) {
  [popovertarget="guide-note"]:not([popovertargetaction]) {
    anchor-name: --guide-trigger;
  }

  #guide-note:popover-open {
    position: fixed;
    position-anchor: --guide-trigger;
    inset: auto;
    margin: 0;
    position-area: block-end span-inline-end;
    position-try-fallbacks: flip-block;
  }
}

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

50
In engines that can resolve the thumb as an anchor, the number follows it. Elsewhere, the updated number stays below the range.
Display the value of a range from 0 to 100
<label for="guide-level">Level</label>
<div id="guide-level-value">
  <input id="guide-level" type="range" min="0" max="100" step="1" value="50">
  <output for="guide-level">50</output>
</div>
#guide-level-value {
  position: relative;
  display: grid;
  padding-inline: 2ch;
}

#guide-level {
  inline-size: 100%;
  min-block-size: 24px;
  margin: 0;
}

#guide-level-value > output {
  font-variant-numeric: tabular-nums;
}

@supports (anchor-name: --guide-thumb) and (position-anchor: --guide-thumb) and (left: anchor(center, -1px)) and (bottom: calc(anchor(top) + 0.25rem)) and (translate: -50%) {
  #guide-level::-webkit-slider-thumb {
    anchor-name: --guide-thumb;
  }

  #guide-level::-moz-range-thumb {
    anchor-name: --guide-thumb;
  }

  #guide-level-value[data-follow-thumb] {
    padding-block-start: 2em;
  }

  #guide-level-value[data-follow-thumb] > output {
    position: absolute;
    position-anchor: --guide-thumb;
    left: anchor(center, -1px);
    bottom: calc(anchor(top) + 0.25rem);
    translate: -50%;
  }
}
const range = document.querySelector('#guide-level');
const example = document.querySelector('#guide-level-value');
const output = example.querySelector('output');

function updateValue() {
  output.value = range.value;
}

range.addEventListener('input', updateValue);
updateValue();

example.setAttribute('data-follow-thumb', '');
const { position, left } = getComputedStyle(output);
if (position !== 'absolute' || !(parseFloat(left) >= 0)) {
  example.removeAttribute('data-follow-thumb');
}

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.

Desktop and mobile compatibility by capability · November 23, 2026
CapabilityBaselineChromeEdgeFirefoxSafari
anchor-nameNewly available · Baseline 2026
position-anchor: --nameNo separate Baseline status
anchor()Newly available · Baseline 2026
position-areaNewly available · Baseline 2026
anchor-scopeNewly available · Baseline 2026
anchor-size()Newly available · Baseline 2026
justify-self: anchor-centerNewly available · Baseline 2026
@position-tryNewly available · Baseline 2026
position-try-fallbacksNewly available · Baseline 2026
position-try-orderNewly available · Baseline 2026
flip-block / flip-inlineNewly available · Baseline 2026
flip-x / flip-yNewly available · Baseline 2026
position-visibility: no-overflowNewly available · Baseline 2026
anchor-valid / anchor-visibleLimited availability
position-anchor: normalNewly available · Baseline 2026
popovertarget → position-anchor: autoNewly available · Baseline 2026
Anchor positioning transformsLimited availability
@container anchored(fallback: …)Limited availability

@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.