CSS Anchor Positioning

Position tooltips, popovers, and dropdowns relative to a trigger element — no Floating UI or JS offset math needed. Pure CSS.

1. Tooltips — position-area: top

Hover any button to show a tooltip positioned above it with position-area: top. Auto-flips below via position-try-fallbacks: flip-block. Zero JS positioning.

Tooltip on Primary button
Tooltip on Success button
Tooltip on Danger button

2. Dropdown Menu — anchor() function

A dropdown positioned with top: anchor(bottom) and left: anchor(left). Flips upward near the bottom of the viewport.

3. Position Area Grid — interactive placement

Select a position-area value to see where the element gets placed relative to the anchor. The 3×3 conceptual grid positions elements around the anchor.

Anchor Element
Positioned here

4. Auto-flip — position-try-fallbacks

Each popover prefers a different side. Scroll or resize the window so the popover would overflow — the browser automatically flips it to the opposite side.

Top popover
I flip to bottom if I would overflow the top edge.
Right popover
I flip to left if I would overflow the right edge.
Bottom popover
I flip to top if I would overflow the bottom edge.
Left popover
I flip to right if I would overflow the left edge.
Implementation: CSS Anchor Positioning (key code)
<!-- HTML: button + popover -->
<button class="tooltip-trigger"
        popovertarget="my-tip">
  Hover me
</button>
<div id="my-tip" popover="manual"
     class="anchor-tooltip">
  Tooltip content
</div>

<style>
  /* Reset conflicting UA popover styles */
  [popover] { margin: 0; inset: auto; }

  /* Name the anchor */
  .tooltip-trigger { anchor-name: --my-btn; }

  /* Position the tooltip */
  .anchor-tooltip {
    position: fixed;
    position-anchor: --my-btn;
    position-area: top;
    margin-bottom: 8px;

    /* Auto-flip to bottom if it overflows */
    position-try-fallbacks: flip-block;

    /* Hide when anchor scrolls away */
    position-visibility: anchors-visible;
  }
</style>

<!-- Dropdown: anchor() for precise edges -->
.anchor-dropdown {
  position: fixed;
  position-anchor: --menu-btn;
  top: anchor(bottom);
  left: anchor(left);
  margin-top: 4px;
  position-try-fallbacks: flip-block;
}