| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/docs/Web/API/Popover_API | [Back] [Original] |
Get to know MDN better
Since January 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
* Some parts of this feature may have varying levels of support.
The Popover API provides developers with a standard, consistent, flexible mechanism for displaying popover content on top of other page content. Popover content can be controlled either using HTML attributes, or via JavaScript.
A very common pattern on the web is to show content over the top of other content, drawing the user's attention to specific important information or actions that need to be taken. This content can take several different names overlays, popups, popovers, dialogs, etc. We will refer to them as popovers through the documentation. Generally speaking, these can be:
Popovers created using the Popover API are always non-modal. If you want to create a modal popover, a <dialog> element is the right way to go. There is significant overlap between the two you might for example want to create a popover that persists, but control it using HTML. You can turn a <dialog> element into a popover (<dialog popover> is perfectly valid) if you want to combine popover control with dialog semantics.
Typical use cases for the popover API include user-interactive elements like action menus, custom "toast" notifications, form element suggestions, content pickers, or teaching UI.
You can create popovers in multiple ways:
Via a set of new HTML attributes. A simple popover with a toggle button can be created using the following code:
<button popovertarget="mypopover">Toggle the popover</button>
<div id="mypopover" popover>Popover content</div>
Via a JavaScript API. For example, HTMLElement.togglePopover() can be used to toggle a popover between shown and hidden.
The Popover API also provides events to react to a popover being toggled and CSS features to aid in styling popovers. See Using the popover API for a detailed guide to the API.
A related feature interest invokers can be used to show popovers on hover/focus, without requiring JavaScript. Check out Using interest invokers to learn more.
interestfor Defines an HTML <a>, <button>, or <area> element, or an SVG <a> element, as an interest invoker. Its value is the id of the target element, which will be affected in some way (normally shown or hidden) when interest is shown or lost on the invoker element.
popoverA global attribute that turns an element into a popover element; takes a popover state ("auto", "hint", or "manual") as its value.
popovertargetTurns a <button> or <input> element into a popover control button; takes the ID of the popover element to control as its value.
popovertargetactionSpecifies the action to be performed ("hide", "show", or "toggle") on the popover element being controlled by a control <button> or <input>.
::backdropThe ::backdrop pseudo-element is a full-screen element placed directly behind popover elements, allowing effects to be added to the page content behind the popover(s) if desired (for example blurring it out).
interest-delay, interest-delay-start, and interest-delay-end The interest-delay shorthand property and its related interest-delay-start and interest-delay-end longhands can be used to add a delay between the user showing or losing interest and the browser acting on that change.
:interest-source and :interest-targetThese selectors can be used to apply styles to the interest invoker and its associated target element, respectively, only when interest is indicated.
:popover-openThe :popover-open pseudo-class matches a popover element only when it is in the showing state it can be used to style popover elements when they are showing.
InterestEvent The event object for the interest and loseinterest events. This includes a source property that contains a reference to the associated interest invoker element.
ToggleEventRepresents an event that fires when a popover element is toggled between being shown and hidden. It is the event object for the beforetoggle and toggle events, which fire on popovers when their state changes.
interestForElement Gets or sets a reference to the element being targeted by an interest invoker. If an HTML or SVG interest invoker references a target element in its interestfor attribute, that element will be referenced in the equivalent DOM object's interestForElement property. Available on the HTMLButtonElement, HTMLAnchorElement, HTMLAreaElement, and SVGAElement interfaces.
HTMLElement.popoverGets and sets an element's popover state via JavaScript ("auto", "hint", or "manual"), and can be used for feature detection. Reflects the value of the popover global HTML attribute.
HTMLButtonElement.popoverTargetElement and HTMLInputElement.popoverTargetElementGets and sets the popover element being controlled by the control button. The JavaScript equivalent of the popovertarget HTML attribute.
HTMLButtonElement.popoverTargetAction and HTMLInputElement.popoverTargetActionGets and sets the action to be performed ("hide", "show", or "toggle") on the popover element being controlled by the control button. Reflects the value of the popovertargetaction HTML attribute.
HTMLElement.hidePopover()Hides a popover element by removing it from the top layer and styling it with display: none.
HTMLElement.showPopover()Shows a popover element by adding it to the top layer.
HTMLElement.togglePopover()Toggles a popover element between the showing and hidden states.
beforetoggle eventFired just before a popover element's state changes between showing and hidden, or vice versa. Can be used to prevent a popover from opening, or to update other elements that need to be triggered by popover state.
toggle eventFired just after a popover element's state changes between showing and hidden, or vice versa.
interest Fired on an interest invoker's target element when interest is shown, allowing code to be run in response.
loseinterest Fired on an interest invoker's target element when interest is lost, allowing code to be run in response.
| Specification |
|---|
| HTML # dom-popover |
| HTML # event-beforetoggle |
| HTML # event-toggle |
popover HTML global attributepopovertarget HTML attributepopovertargetaction HTML attribute::backdrop CSS pseudo-element:popover-open CSS pseudo-classThis page was last modified on Dec 17, 2025 by MDN contributors.
HTMLButtonElement.popoverTargetActionHTMLButtonElement.popoverTargetElementHTMLElement.popoverHTMLInputElement.popoverTargetActionHTMLInputElement.popoverTargetElementHTMLAnchorElement.interestForElementHTMLAreaElement.interestForElementHTMLButtonElement.interestForElementSVGAElement.interestForElementYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |