CSS Anchor Positioning in Practice: Tooltips, Menus, and Popovers Without JavaScript

December 2, 2026

Core model

CSS anchor positioning lets a positioned element attach itself to another element without wrapper hacks or JavaScript measurements. The anchor is marked with anchor-name; the floating layer uses position-anchor or the anchor() function.

css code editor screen

A minimal tooltip looks like this:

.info-button { anchor-name: --tip-button; }
.tip { position: fixed; position-anchor: --tip-button; top: anchor(bottom); justify-self: anchor-center; }

Keep two rules in mind. First, the anchored element usually needs position: fixed. Second, clipping ancestors can still affect it: overflow: hidden, transforms, filters, and containing-block quirks can create boundaries even for fixed positioning.

ui tooltip dropdown design

Tooltip

A tooltip should be small, secondary, and usually opened on hover or focus. Use a button as the anchor so keyboard users can reach it naturally.

<button class="hint" aria-describedby="save-tip" type="button">Save</button>
<span id="save-tip" class="tooltip" role="tooltip">Saves the draft and keeps editing</span>

.hint {
  anchor-name: --save-button;
}

.tooltip {
  position: fixed;
  position-anchor: --save-button;
  top: calc(anchor(bottom) + 8px);
  justify-self: anchor-center;
  max-width: 240px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #1f2937;
  color: white;
  font-size: 13px;
}

.hint:hover .tooltip,
.hint:focus-visible + .tooltip {
  display: block;
}

This markup assumes the tooltip is a following sibling. If it lives elsewhere in the DOM, hover-only CSS will not reach it. In that case, use :has() on a common parent, or accept a small JavaScript toggle.

Dropdown: prefer disclosure semantics

For a navigation list, do not add role="menu" just because it looks like a menu. A native disclosure with links is usually more robust.

<nav class="disclosure-nav" aria-label="Products">
  <button class="disclosure-button" aria-expanded="false" aria-controls="product-panel" type="button">
    Products
  </button>
  <div id="product-panel" class="dropdown" hidden>
    <a href="/css/">CSS tools</a>
    <a href="/icons/">Icons</a>
    <a href="/templates/">Templates</a>
  </div>
</nav>

Without JavaScript, you can use the popover attribute for a light-dismiss disclosure:

<button popovertarget="product-panel" class="disclosure-button">Products</button>
<div id="product-panel" class="dropdown" popover>...</div>

The CSS anchors the panel below the button:

.disclosure-button {
  anchor-name: --products-button;
}

.dropdown {
  position: fixed;
  position-anchor: --products-button;
  inset: auto;
  top: calc(anchor(bottom) + 6px);
  left: anchor(left);
  min-width: max-content;
  max-width: 320px;
  margin: 0;
  padding: 8px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 12px 30px rgb(0 0 0 / 14%);
}

.dropdown a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: #111827;
}

.dropdown a:hover,
.dropdown a:focus-visible {
  background: #f3f4f6;
}

If you truly use role="menu" and role="menuitem", arrow-key navigation, roving tabindex, Home/End, and typeahead expectations come with it. CSS positioning does not provide that behavior.

Popover

The Popover API supplies open and close behavior, top-layer rendering, Escape dismissal, and light-dismiss. Anchor positioning then handles placement. This combination gets closer to a JavaScript-free floating layer.

<button class="share-button" popovertarget="share-popover" type="button">
  Share
</button>

<div id="share-popover" class="popover-card" popover="auto">
  <h2>Share project</h2>
  <p>Copy a private link or invite teammates by email.</p>
  <label>Email<input type="email"></label>
  <button type="button">Send invite</button>
</div>
.share-button {
  anchor-name: --share-button;
}

.popover-card {
  position: fixed;
  position-anchor: --share-button;
  inset: auto;
  top: calc(anchor(bottom) + 10px);
  justify-self: anchor-center;
  width: max-content;
  max-width: min(360px, calc(viewport-width - 24px));
  padding: 16px;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  background: white;
  box-shadow: 0 20px 50px rgb(0 0 0 / 18%);
}

.popover-card:popover-open {
  display: block;
}

Use popover="auto" for normal light-dismiss panels. Use popover="manual" only when you explicitly control closing, because it will not close on outside click or Escape by itself.

Position-try fallbacks and constraints

@position-try defines named fallback placements. Assign them with position-try-fallbacks. The browser tries the preferred placement and switches when the element would overflow.

.popover-card {
  position: fixed;
  position-anchor: --share-button;
  inset: auto;
  top: calc(anchor(bottom) + 10px);
  justify-self: anchor-center;
  max-width: var(--max-width, 360px);
  max-height: var(--max-height, 480px);
  overflow: auto;
  position-try-fallbacks: --flip-top, --shift-left, --shift-right;
}

@position-try --flip-top {
  top: auto;
  bottom: calc(anchor(top) + 10px);
  justify-self: anchor-center;
}

@position-try --shift-left {
  top: calc(anchor(bottom) + 10px);
  justify-self: anchor-right;
  --max-width: calc(anchor(left) - 12px);
}

@position-try --shift-right {
  top: calc(anchor(bottom) + 10px);
  justify-self: anchor-left;
  --max-width: calc(viewport-width - anchor(right) - 12px);
}

@supports not (position-try-fallbacks: --x) {
  .popover-card {
    max-width: min(360px, calc(viewport-width - 24px));
  }
}

For older syntax in Chromium previews, you may see position-try-options. Treat that as a transitional vendor path, not the main production declaration.

Scroll containers, overflow, and containing blocks

Anchored popovers follow their anchor during scrolling when the browser supports anchor positioning. But clipping is still easy to accidentally introduce.

Reproduce the common failure:

<div class="page-section">
  <button class="anchor-button" popovertarget="clipped-pop">Open</button>
  <div id="clipped-pop" popover>I may be clipped</div>
</div>

.page-section {
  overflow: hidden;
  height: 120px;
  border: 1px dashed #9ca3af;
}

.anchor-button { anchor-name: --clipped; }
#clipped-pop {
  position: fixed;
  position-anchor: --clipped;
  top: anchor(bottom);
}

Because .page-section clips overflow, the panel can disappear at the edge. Similar effects happen when an ancestor uses transform, perspective, filter, contain: paint, or will-change: transform.

Practical fixes:

    <li>Render popovers as top-layer elements, outside clipping layout wrappers.</li> <li>Replace overflow: hidden with overflow: clip only after testing; behavior with fixed descendants still needs care.</li> <li>Move the anchored node to the body if legacy browsers require it.</li> <li>Constrain panel size with max-width, max-height, and internal overflow: auto.</li> </ul>

    Accessibility

    Tooltips

    Use aria-describedby for supplementary text. Do not put essential instructions only in a hover tooltip. Focus must show the same content as hover. Add a visible dismissal path on touch, or avoid hover-only tooltips there. Small touch targets and no hover state make CSS-only tooltips unreliable.

    Disclosure navigation

    A button with aria-expanded and aria-controls is the right base for a link list. With the Popover API, the browser manages the open state and Escape. Focus should remain on the trigger when opening; Tab then moves into links. On close, return focus to the trigger if the user dismissed it from inside the panel.

    Popovers

    popover="auto" closes on Escape and outside activation. It renders in the top layer, so z-index wars disappear. If the popover contains a form, autofocus the first field with the autofocus attribute, but only when opening should move focus. For a passive preview, keep focus on the trigger.

    Touch devices need adequately sized targets and no hover-dependent actions. Keyboard users need visible focus rings, logical Tab order, and a way to close and return where they started.

    Browser support and fallbacks

    Check current support before shipping. MDN documents CSS anchor positioning and the Popover API separately; Can I Use tracks Chrome, Edge, Safari, and Firefox versions. As of recent releases, anchor positioning is available in Chromium browsers such as Chrome 125+ and Edge 125+, while Safari and Firefox support should be verified in the current release tables because their implementations have landed more recently. Popover support is available in Chrome/Edge 114+, Safari 17+, and Firefox 125+.

    Use progressive enhancement:

    .dropdown,
    .popover-card {
      position: absolute;
    }
    
    @supports (anchor-name: --a) {
      .dropdown,
      .popover-card {
        position: fixed;
        position-anchor: var(--anchor);
      }
    }

    For unsupported browsers, choose one of two paths. The simple path is absolute positioning inside a position: relative wrapper, accepting viewport-edge and overflow limitations. The robust path is Floating UI, which computes top, left, flipping, shifting, and collision detection in JavaScript.

    Do not advertise a component as completely JavaScript-free if it needs focus restoration, full ARIA menu keyboard behavior, complex outside-click handling, positioning in clipping containers, or legacy-browser support. Native CSS and popovers can remove a lot of script, but not every interaction requirement.