--- url: "https://web.dev/blog/popover-api" titulek: "Popover API lands in Baseline | Blog | web.dev" h1: "Popover API lands in Baseline Stay organized with collections Save and categorize content based on your preferences." popis: "The popover API lands in all modern browser engines." jazyk: "en" kanonicka: "https://web.dev/blog/popover-api" drobecky: ["Blog", "Popover API lands in Baseline"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:03:06" znaku: 4942 slov: 704 kodovani: "iso-8859-2" sha256: "613840a09213f2a99a3314b192049e284a9bf1c9bde9d1701689390355879323" --- Popover API lands in Baseline Stay organized with collections Save and categorize content based on your preferences. Una Kravets It's happening! One of the features I am most hyped about has just landed across all modern browsers and is officially a part of Baseline 2024. And this feature is the [Popover API](https://developer.mozilla.org/docs/Web/API/Popover_API). Popover provides so many awesome primitives and developer affordances for building layered interfaces like tooltips, menus, teaching UIs, and more. Browser Support 114 114 125 17 [Source](https://developer.mozilla.org/docs/Web/API/HTMLButtonElement/popoverTargetAction) Some quick highlights of popover capabilities include: **Promotion to the top layer.** Popovers will appear in the [top layer](https://developer.chrome.com/blog/what-is-the-top-layer) above the rest of the page, so you don't have to play around with `z-index`. **Light-dismiss functionality.** Clicking outside of the popover area will close the popover and return focus. **Default focus management.** Opening the popover makes the next tab stop inside the popover. **Accessible keyboard bindings.** Hitting the `esc` key or double toggling will close the popover and return focus. **Accessible component bindings.** Connecting a popover element to a popover trigger semantically. Creating popovers Creating popovers is quite straightforward. To use default values, all you need is a `button` to trigger the popover, and an element to trigger. First, set a `popover`attribute on the element which is going to be the popover. Then, add an unique `id` on the popover element. Finally, to connect the button to the popover, set the button's `popovertarget`to the value of the popover element's `id`. This is shown in the following code: `

I am a popover with more information. Hit esc or click away to close me.

` A basic example of using the popover attribute. To have more granular control over the popover, you can explicitly set types of popovers. For example, using a bare `popover` attribute with no value is the same as `popover="auto"`. The `auto` value enables light-dismiss behavior and automatically closes other popovers. Use `popover="manual"` and you will need to add a close button, manual popovers don't close other popovers or allow users to dismiss the popover by clicking away in the UI. You create a manual popover using the following: `

I am a popover with more information. Hit the close button or toggle to close me.

` An example of a manual popover. You may be wondering if you need popover when dialog exists, and the answer is: you might not. It's important to note that the popover attribute does not provide semantics on its own. And while you can now build modal dialog-like experiences using popover, there are a few key differences between the two: Opened with `dialog.showModal()`. Closed with `dialog.close()`. Makes the rest of the page inert. Does not support light-dismiss behavior. You can style the open state with the `[open]` attribute. Semantically represents an interactive component that blocks interaction with the rest of the page. The `[popover]` attribute Can be opened with a declarative invoker (`popovertarget`). Closed with `popovertarget` (auto popover) or `popovertargetaction=hide` (manual popover). Does not make the rest of the page inert. Supports light-dismiss behavior. You can style the open state with the `:popover-open` pseudo-class. No inherent semantics. Conclusion and further reading There are many exciting features that `popover` brings to the platform. To learn more about this API, including more on the accessibility of the feature, and documentation regarding the feature set, here is some recommended reading for further information: [Semantics and the popover attribute: what to use when? by Hidde de Vries](https://hidde.blog/popover-semantics/) [On popover accessibility: what the browser does and doesn't do by Hidde de Vries](https://hidde.blog/popover-accessibility/) [MDN documentation on popover](https://developer.mozilla.org/docs/Web/HTML/Global_attributes/popover) Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2024-04-25 UTC.