Live Demo

Click the button below to see the anchored popover in action:

About This Demo

This demo showcases modern web platform features that work together to create an elegant, accessible popover menu. The demonstration combines cutting-edge CSS and HTML capabilities to deliver a smooth user experience without requiring JavaScript.

Main Features

HTML Popover API

The Popover API provides a standardized way to create overlay content that appears on top of other page content. This demo uses the popover attribute on the navigation element and popovertarget on the button to create the relationship between trigger and content. This approach offers several advantages:

The popover automatically manages focus, provides keyboard navigation, and handles the display state without custom scripting.

<button popovertarget="my-popover">Open</button>

<div id="my-popover" popover>
  Popover content here
</div>

Learn more: MDN - Popover API

CSS Anchor Positioning

CSS Anchor Positioning allows elements to be positioned relative to other elements on the page, solving a long-standing challenge in web development. In this demo, the popover menu is anchored to the button that triggers it, ensuring it appears in the correct location regardless of where the button is positioned on the screen.

This feature enables:

The anchor-position property creates a stable, maintainable connection between the trigger and the popover content.

#trigger {
  anchor-name: --my-anchor;
}

#popover {
  position-anchor: --my-anchor;
  top: anchor(bottom);
  left: anchor(left);
}

Learn more: MDN - CSS Anchor Positioning

CSS Corner Shape

The corner-shape property adds visual polish by creating custom corner styles beyond traditional border-radius. This demo uses it to create a distinctive corner appearance on the popover menu, enhancing the visual design and helping the popover stand out from standard rectangular containers.

Benefits include:

This property allows designers to create more sophisticated and branded interface elements with minimal code.

button {
  border-radius: 1rem;
  corner-shape: squircle;
}

Learn more: MDN - corner-shape

CSS Position Try Fallbacks

The position-try-fallbacks property works hand-in-hand with anchor positioning to provide intelligent fallback positioning when the primary position would cause overflow or visibility issues. This ensures popovers and tooltips always remain visible and accessible, even in constrained viewport scenarios.

Key capabilities:

This feature eliminates the need for JavaScript-based collision detection and repositioning logic, making popover positioning more robust and performant.

@position-try --top-left {
  top: anchor(top);
  bottom: auto;
  left: anchor(left);
}

#popover {
  position-anchor: --my-anchor;
  top: anchor(bottom);
  left: anchor(left);
  position-try-fallbacks: --top-left, flip-block, flip-inline;
}

Learn more: MDN - position-try-fallbacks

CSS Interpolate Size

The interpolate-size property enables smooth animations and transitions to intrinsic sizing keywords like auto, fit-content, min-content, and max-content. Previously, animating to these values required JavaScript calculations or workarounds like using max-height with arbitrary large values.

Key benefits:

This property must be set globally on :root or html to enable the feature across all elements. While powerful, browser support is still emerging, and some combinations (like height transitions on popovers) may not work reliably yet.

:root {
  interpolate-size: allow-keywords;
}

.element {
  height: 0;
  transition: height 300ms ease;
}

.element.expanded {
  height: fit-content;
}

Learn more: MDN - interpolate-size


CSS @starting-style

The @starting-style rule defines the initial state of an element when it first appears in the DOM or enters the top layer (like popovers and dialogs). This enables smooth entry animations without requiring JavaScript to toggle classes or manipulate styles.

Use cases:

When combined with transitions and the allow-discrete keyword, @starting-style enables complete control over element appearance animations. The browser automatically interpolates from the @starting-style values to the element's normal state.

.popover {
  opacity: 1;
  transform: scale(1);
  transition: opacity 300ms, transform 300ms,
              display 300ms allow-discrete;
}

.popover:popover-open {
  @starting-style {
    opacity: 0;
    transform: scale(0.8);
  }
}

Learn more: MDN - @starting-style

These features work harmoniously to create a polished, accessible popover experience that demonstrates the power of modern web standards.