CSS Anchor Positioning Fallbacks: When anchor() Isn’t Supported Yet

December 6, 2026

Support detection rules

There is no anchoring() function in CSS Anchor Positioning. The pieces to check are:

web developer code screen
  • anchor-name: accepts a dashed ident, such as --menu-button.
  • anchor(): used inside anchored element insets, for example left: anchor(right);.
  • position-anchor: links an anchored element to an anchor name, such as position-anchor: --menu-button;.
  • position-area: places an element in an area relative to its anchor. Older implementations used inset-area; do not rely on that name in production without a fallback.
  • position-try-fallbacks: formerly exposed in some places as position-try-options. Use the standard property when available, but treat fallback options as progressive enhancement.

A conservative detection layer checks the core anchor-name and anchor-function syntax:

@supports (anchor-name: --a) and (top: anchor(bottom)) { ... }

Do not assume every related property is available just because that block passes. position-area and position-try-fallbacks need their own checks or should be kept in non-critical enhancement layers. Verify current behavior in MDN/Browser Monitor and your target browsers before shipping. A practical pattern is: ship robust absolute positioning first, then add anchor positioning inside @supports.

dropdown menu interface

Choose the positioning layer before writing CSS

ApproachBest forOverflow / clippingRepositioningNotes
Wrapper + position: absoluteDropdowns, simple tooltips where trigger and popup are adjacent in the DOMClipped by overflow: hidden, transformed ancestors, and stacking contextsAutomatic with normal flowSmallest JS surface; easiest accessible pattern
Root/portal + getBoundingClientRect()Popovers rendered at <body>, portals, hidden containersAvoids ancestor clippingListen to scroll, resize, and anchor changesNeeds explicit collision handling and cleanup
CSS anchor positioningModern browsers and components that can safely layer enhancementsCan escape some overflow clipping depending on layout and browser implementationCSS handles movement; try fallbacks handle edgesStill needs fallbacks for older browsers

Do not use CSS anchors as the only positioning method for critical date pickers, menus, or onboarding bubbles. Also avoid them when you must support transformed ancestor behavior consistently, when the popup is portaled far from the trigger, or when you already have a mature floating-ui-style positioning layer.

Complete dropdown: wrapper absolute, then CSS anchors

This is the steadiest default: a relatively positioned wrapper keeps the trigger and popup together.

<div class="menu">
  <button id="menuBtn" aria-haspopup="menu" aria-expanded="false" aria-controls="menuList">Actions</button>
  <div id="menuList" class="menu__popup" role="menu" hidden>
    <button role="menuitem">Edit</button>
    <button role="menuitem">Duplicate</button>
  </div>
</div>
.menu { position: relative; }
.menu__popup {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 180px;
  background: #fff;
  border: 1px solid #d7dce3;
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(20, 30, 50, .14);
  z-index: 10;
}

@supports (anchor-name: --a) and (top: anchor(bottom)) {
  .menu button { anchor-name: --menu-button; position-anchor: --menu-button; }
  .menu__popup {
    position: fixed;
    top: anchor(bottom);
    left: anchor(left);
    margin-top: 8px;
    position-try-fallbacks: flip-block, flip-inline;
  }
}

Open with hidden = false, set aria-expanded, move focus to the first item, close on Esc, and return focus to the trigger. For the absolute version, avoid placing overflow: hidden on a scroll container between the wrapper and popup unless clipping is intended.

Tooltip geometry without double translation

A common bug is mixing two centering systems. If you write left: anchor(center), you are aligning the tooltip’s left edge to the anchor’s center, unless you also compensate. Pick one method.

Method A: side keyword plus translate

.tip {
  position: absolute;
  top: auto;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
}

Method B: anchor insets with margins

@supports (anchor-name: --a) and (left: anchor(center)) {
  [data-tooltip-trigger] { anchor-name: --tip-anchor; }
  .tip {
    position: fixed;
    position-anchor: --tip-anchor;
    bottom: anchor(top);
    left: anchor(center);
    translate: -50% 0;
    margin-bottom: 8px;
  }
}

Here anchor(center) refers to the center line of the anchor box. The tooltip still needs translateX(-50%) because its left edge is placed on that line. Do not also use left: 50%; that usually moves it twice.

Tooltips should usually be aria-describedby associations, not focusable elements. Show them on hover and focus, keep them open while the pointer moves toward them, and never hide critical information inside hover-only UI.

Root-level popover: two real fallbacks

Fallback 1: DOM-adjacent pure CSS absolute positioning

Use this when you can render the popover immediately after its trigger in normal DOM order and no ancestor clips it.

<div class="pop-wrap">
  <button popovertarget="profile" id="profileBtn" aria-expanded="false">Profile</button>
  <div id="profile" popover="auto" class="pop" aria-labelledby="profileBtn">...</div>
</div>
.pop-wrap { position: relative; }
.pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(320px, 90vw);
}
@supports (anchor-name: --a) and (top: anchor(bottom)) {
  #profileBtn { anchor-name: --profile-btn; }
  .pop {
    position: fixed;
    position-anchor: --profile-btn;
    top: anchor(bottom);
    right: anchor(right);
    margin-top: 8px;
  }
}

This is simple, but it fails when an ancestor has overflow: hidden, contain: paint, or a transform that becomes a containing block.

Fallback 2: portal plus getBoundingClientRect coordinates

Use this when the popover is rendered at the document root, inside a portal, or the trigger lives in a clipping/transformed container.

const pop = document.querySelector('#profile');
const btn = document.querySelector('#profileBtn');

function placePop() {
  const b = btn.getBoundingClientRect();
  const width = 320;
  const gap = 8;
  let left = b.right - width;
  let top = b.bottom + gap;

  left = Math.max(8, Math.min(left, innerWidth - width - 8));
  if (top + pop.offsetHeight > innerHeight - 8) top = b.top - pop.offsetHeight - gap;

  pop.style.position = 'fixed';
  pop.style.top = `${top}px`;
  pop.style.left = `${left}px`;
}

btn.addEventListener('click', () => {
  pop.togglePopover();
  placePop();
});

window.addEventListener('resize', placePop);
document.addEventListener('scroll', placePop, true);

Use position: fixed with viewport coordinates from getBoundingClientRect(). Capture-phase scroll listening helps when the trigger scrolls inside a nested container. Remove listeners when the popover closes or unmounts, and use ResizeObserver if either the trigger or popup can change size.

For basic edge handling, flip vertically when there is more space above, clamp horizontally to the viewport, and add 8px viewport padding. If your product needs shifting, flipping, nested scroll containers, and arrow alignment everywhere, use a maintained positioning utility rather than growing this helper by hand.

Edge cases that break assumptions

  • Transforms and filters: ancestors can become containing blocks for fixed-position fallbacks.
  • Overflow: wrapper absolute is easiest to clip; root portals avoid most ancestor clipping.
  • Scrolling: CSS anchors and wrapper absolute follow layout automatically; portal JavaScript must update coordinates.
  • Resizing: portal popovers need resize observers and window resize handling.
  • Browser syntax drift: keep position-area and position-try-fallbacks in enhancement layers; never make core open/close behavior depend on them.
  • Hidden content: measure after removing hidden or after the popover is shown, or dimensions will be zero.

Shipping checklist

  1. Start with accessible HTML: buttons, aria-expanded, aria-controls, menu roles only for real menus, and visible focus styles.
  2. Ship wrapper absolute positioning for adjacent DOM components.
  3. Use portal + getBoundingClientRect() for root-level or clipped popovers.
  4. Add CSS anchor positioning inside a tested @supports block.
  5. Avoid duplicate centering transforms.
  6. Handle Esc, outside clicks, scroll, resize, and focus return.
  7. Test near viewport edges, nested scroll containers, transformed ancestors, and mobile zoom.