The popover Attribute
How popover and popovertarget give you menus and tooltips without JavaScript: auto vs manual, light dismiss, nesting, events, and when to use dialog instead.
The popover Attribute
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Adding `popover` to an element hides it by default and puts it in the top layer when shown. A `<button popovertarget="id">` toggles it with no script.
- `popover` (same as `auto`) light-dismisses: a click outside or Escape closes it, and opening another auto popover closes the first. `popover="manual"` does neither.
- A popover is not modal. In a test the page behind stayed interactive, and Tab moved from the invoker into the open popover.
- The invoker button reports `expanded` itself. In a test it flipped from false to true when the popover opened, with no ARIA in the markup.
- `popovertargetaction` can be `show`, `hide` or `toggle`. Events are `beforetoggle` and `toggle`, and `:popover-open` matches the open state.
Light overlays are everywhere
Menus, tooltips, date pickers, “more actions” lists. Each is a small layer that opens next to a control, closes when you click elsewhere, and sits above the rest. Before the popover attribute you needed a state variable, a click-outside listener, an Escape listener, a z-index and aria-expanded bookkeeping.
The browser now does it declaratively:
<button popovertarget="menu">Menu</button>
<div id="menu" popover>
<a href="/profile">Profile</a>
<a href="/logout">Log out</a>
</div>
web-features marks popover as Baseline, newly available since 27 January 2025 (Chrome 116, Firefox 125, Safari 17).
What I observed
I tested this in Chromium 159, Firefox 159 and a WebKit build.
- Closed means hidden. A popover has
display: noneuntil shown, and is in the top layer when open. - Toggle by default. Clicking the invoker twice opened then closed it. With
popovertargetaction="show", two clicks left it open. - Auto light dismiss. Clicking outside, or pressing Escape, closed it. Opening a second auto popover closed the first.
- Manual does not. With
popover="manual", clicking outside and Escape both left it open. Your code must callhidePopover()or use a button. - Nesting. A popover opened from a button inside another popover kept its parent open. Both closed on an outside click.
- Not modal. The page behind stayed clickable. Pressing Enter on the invoker left focus on the invoker, and Tab moved into the popover in Chromium and Firefox. In the WebKit build, the next Tab left the document instead.
- Accessibility. In Chromium’s tree the invoker had
expanded=false, thenexpanded=trueonce open. The ARIA lesson says native elements should do this for you; this is an example.
The JS surface is small: showPopover(), hidePopover(), togglePopover(), the :popover-open pseudo-class, and beforetoggle and toggle events with oldState and newState. The popover="hint" value (for tooltips that shouldn’t close other popovers) and the source option on showPopover() both worked in the builds I ran, but web-features lists hint as not yet Baseline (Chrome 151, Firefox 153, nothing for Safari), so check support before using it.
Popover versus dialog
Both live in the top layer, and the differences are about interruption. dialog.showModal() traps focus, makes the page inert and has a backdrop. A popover lets the user carry on. Use dialog for decisions, and popover for contextual menus and pickers. Popovers do not position themselves next to the invoker. They sit centred by default, and placing them is a job for CSS anchor positioning, covered in anchor positioning and popovers.
One caution: a popover is not a replacement for a title tooltip on keyboard focus, since a popover opens on click or key press, not on hover or focus.
What the video covers
This is episode 079 of The CSS Podcast, “Popover and Dialog” (June 2024, about 20 minutes). The description says it highlights the popover API and the dialog element, what they can do, and when to use which, with links to Chrome’s posts on dialogs versus popovers and on the semantics of the popover attribute. It is audio-led. I could not read a transcript, so I can’t say how it demonstrates anything. The behaviours above are my own browser tests, and Coding in Public’s tutorial adds a hands-on tour.
Where this fits
This follows the dialog element and the ARIA lesson. Next, data attributes start the group’s move toward scriptable HTML.
Check yourself
What is the difference between `popover` and `popover="manual"`?
An auto popover closes on outside click and on Escape, and opening another auto popover closes it. A manual one does neither: in a test, clicking outside and pressing Escape left it open. Use manual when your own code decides when it closes.
Two popovers are open: a menu and a submenu invoked from inside it. Why does the menu not close when the submenu opens?
An auto popover opened from within another auto popover is its descendant, so the ancestor stays open. In a test a parent and the child it invoked were both open until a click outside closed both.
You open a popover with the keyboard. Where is focus, and how does the user reach the content?
Focus stays on the invoker. Pressing Tab moved into the popover in Chromium and Firefox in a test. That is different from `showModal()`, which moves focus in for you.
When should you pick `dialog` instead?
When the user must respond before continuing: confirmations, forms that block, anything that needs focus trapped and the page made inert. Popovers suit menus, tooltips and pickers where the user can click away.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.