popover
Zero-JavaScript popovers, menus, and tooltips via the native Popover API. VB provides styling for popovers and tooltip variants.
Overview
The Popover API lets you create overlay content with zero JavaScript. Elements with the popover attribute are hidden by default, appear in the browser's top layer when shown, and get light-dismiss behavior (click outside or press Escape to close).
VB provides styling for popovers and a tooltip variant. The Popover API replaces many cases that previously required JavaScript modal/dropdown libraries.
The popover Attribute
Add popover to any element to make it a popover. The element is hidden by default and shown when triggered.
| Value | Behavior |
|---|---|
popover (or popover="auto") | Light-dismiss: closes when clicking outside or pressing Escape. Only one auto popover is visible at a time. |
popover="manual" | No light-dismiss. Must be closed explicitly via button or JavaScript. Multiple manual popovers can be open simultaneously. |
Live demo
Click outside or press Escape to close.
Trigger Attributes
Any button can control a popover using these attributes.
| Attribute | Purpose |
|---|---|
popovertarget="id" | References the popover element's id |
popovertargetaction | Controls what happens: toggle (default), show, or hide |
Tooltip Variant
VB styles [role="tooltip"][popover] as a compact tooltip. This combines the Popover API's positioning and dismiss behavior with ARIA's tooltip semantics.
For more advanced tooltip behavior (hover triggers, arrow positioning), see the <tooltip-wc> web component.
Menu Pattern
A navigation menu built entirely with native HTML:
Nested Popovers
Auto popovers can nest. When a child popover opens, its parent stays open. Clicking outside closes all of them.
Styling
VB provides base styles for [popover] elements including padding, border, border-radius, and box-shadow. The ::backdrop pseudo-element is available for manual popovers.
Popovers render in the browser's top layer, which means they appear above all other content regardless of z-index. No z-index wars.
Comparison
| Feature | Popover API | <dialog> |
|---|---|---|
| Light dismiss | Auto popovers only | No |
| Top layer | Yes | Only with showModal() |
| Backdrop | Yes | Yes (modal only) |
| Focus trapping | No | Yes (modal only) |
| JavaScript required | No | Yes (showModal()) |
| Best for | Menus, tooltips, dropdowns | Modal dialogs, confirmations |
See Also
<dialog>for modal dialogs<tooltip-wc>for hover-triggered tooltips<dropdown-wc>for rich dropdown menus