Since April 2024, 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 showPopover() method of the HTMLElement interface shows a popover element (i.e., one that has a valid popover attribute) by adding it to the top layer.
When showPopover() is called on an element with the popover attribute that is currently hidden, a beforetoggle event will be fired, followed by the popover showing, and then the toggle event firing. If the element is already showing, an error will be thrown.
showPopover() showPopover(options)
options OptionalAn object that can contain the following properties:
source OptionalAn HTMLElement reference; programmatically defines the invoker of the popover associated with the show action, that is, its control element. Establishing a relationship between a popover and its invoker using the source option has two useful effects:
None (undefined).
InvalidStateError DOMException
Thrown if the popover is already showing.
The following example provides functionality to show a popover by pressing a particular key on the keyboard.
First, some HTML:
<div id="mypopover" popover>
<h2>Help!</h2>
<p>You can use the following commands to control the app</p>
<ul>
<li>Press <ins>C</ins> to order cheese</li>
<li>Press <ins>T</ins> to order tofu</li>
<li>Press <ins>B</ins> to order bacon</li>
<hr />
<li>Say "Service" to summon the robot waiter to take your order</li>
<li>Say "Escape" to engage the ejector seat</li>
</ul>
</div>
And now the JavaScript to wire up the functionality:
const popover = document.getElementById("mypopover");
document.addEventListener("keydown", (event) => {
if (event.key === "h") {
popover.showPopover();
}
});
| Specification |
|---|
| HTML> # dom-showpopover> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
showPopover |
114 | 114 | 125 | 100 | 17 | 114 | 125 | 76 | 17 | 23.0 | 114 | 17 |
options_source_parameter |
133When using this option, the focus order doesn't change, so the popover does not become the next focus element. See bug 383343310. |
133When using this option, the focus order doesn't change, so the popover does not become the next focus element. See bug 383343310. |
141 | 118When using this option, the focus order doesn't change, so the popover does not become the next focus element. See bug 383343310. |
previewWhen using this option, the focus order doesn't change, so the popover does not become the next focus element. See bug 286575. |
133When using this option, the focus order doesn't change, so the popover does not become the next focus element. See bug 383343310. |
141 | 88When using this option, the focus order doesn't change, so the popover does not become the next focus element. See bug 383343310. |
No | No | 133When using this option, the focus order doesn't change, so the popover does not become the next focus element. See bug 383343310. |
No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/showPopover