Overlays & display
Popover
Popover
Demo
Loading demo…
A small panel that opens when you click a button and stays attached to it. It shows actions, a picker or a short form without blocking the page, and closes when you click outside.
Story
Did you know
For years, the number one cause of dropdown bugs was a parent with overflow: hidden or a z-index set too low. The Popover API's top layer fixes that at the browser level.
Timeline
- 2010sBootstrap and jQuery UI popularize JS dropdowns and popovers.
- 2015Popper.js (now Floating UI) standardizes positioning.
- 2024The Popover API becomes available in every browser.
Vocabulary
Names
- FR
- Popover, bulle contextuelle, menu déroulant, menu d'actions
- EN
- Popover, dropdown, flyout, popup menu, menu button
Common uses
- "…" action menus on a row
- Pickers (date, emoji, color)
- Profile preview on hover
- Small forms attached to a button
Often paired with
The components it usually sits with, by page type, in reading order.
Product page
See the mock-upCode
<button class="trigger" popovertarget="actions">Actions</button>
<div id="actions" popover>
<button>Rename</button>
<button>Duplicate</button>
<button>Delete</button>
</div>
<style>
.trigger { anchor-name: --actions; }
#actions {
position-anchor: --actions;
inset: auto; margin: 4px 0 0;
top: anchor(bottom); left: anchor(left);
position-try-fallbacks: flip-block;
}
</style>
<script>
actions.addEventListener('click', e => {
const item = e.target.closest('button')
if (!item) return
console.log(item.textContent)
actions.hidePopover()
})
</script>Good to know
- The
popoverattribute gives you the top layer (no morez-indexwars oroverflow: hiddenparents), closing on outside click and Escape, with no JS.popovertargetonly works on a<button>or an<input>. - By default the browser centers the popover on screen. Reset
insetandmarginbefore placing it with CSS Anchor Positioning. Otherwise, Floating UI is still the go-to library. position-try-fallbacks: flip-blockflips it above the button when there is no room below. In a list, give each row its ownanchor-name.popover="auto"closes other open popovers,popover="manual"leaves everything to you. A popover doesn't block: if people must answer before going on, you need a modal.
Accessibility
Must have
- The trigger is a real
<button>with a clear name. A lone "…" icon needs anaria-label. - With
popovertarget, the browser exposes the button's open state (implicitaria-expanded). In a home-made version, setaria-expandedandaria-controlsyourself. - With the keyboard, Tab moves from the button into the popover content. Escape closes it and returns focus to the button.
Often forgotten
role="menu"commits you to arrow keys, Home, End androle="menuitem"(the APG Menu Button pattern). Without that keyboard support, plain buttons with no role are better.- A popover that only opens on hover is out of reach for touch and keyboard users.
Nice to have
- Add
aria-haspopup="menu"to the button when it is a real menu. - Animate the opening with
@starting-styleandtransition-behavior: allow-discrete, while respectingprefers-reduced-motion.