StealThis .dev

Native Popover API Menu

A zero-dependency showcase of the native HTML Popover API — a dropdown menu, hint tooltip, and modal-style dialog built purely from the popover and popovertarget attributes. Light-dismiss, the top layer, Escape handling, and backdrop styling come for free from the browser, with an optional CSS Anchor Positioning variant gated behind @supports so tethered popovers snap to their trigger without a single line of positioning JavaScript.

Open in Lab
vanilla-js css
Targets: JS HTML

Code

Native Popover API Menu

This demo leans entirely on the HTML Popover API — the popover attribute plus popovertarget on a button — to open three distinct overlay patterns without any positioning library. The account dropdown menu and the info tooltip use popover="auto", so the browser handles the top layer, light-dismiss (click outside or press Escape), and only-one-open-at-a-time semantics. The confirmation dialog uses popover="manual" to stay put until the user makes a choice, giving you a modal-ish flow with a styled ::backdrop.

Every open element is promoted to the browser’s top layer, so it always paints above surrounding content with no z-index juggling. You can drive popovers declaratively (a plain button with popovertarget) or imperatively with showPopover(), hidePopover(), and togglePopover() — the toolbar buttons below show both. The beforetoggle and toggle events keep the trigger’s aria-expanded state and a live status log in sync.

For tethered placement the menu upgrades progressively: a @supports (anchor-name: --x) block wires the dropdown to its button with CSS Anchor Positioning (anchor-name / position-anchor / anchor()), so it follows the trigger natively. Browsers without anchor support fall back to a sensible absolute layout, and a runtime feature check surfaces exactly which capabilities your browser has.