HTML global attributeGlobal attributes

popover

Turns an element into a pop-up opened by a button, without JavaScript.

Applies to
All HTML elements
On this page

Example

#
HTML
<button popovertarget="menu" type="button">Open menu</button>

<div id="menu" popover style="padding: 16px; border-radius: 12px; border: 1px solid #444;">
  <p style="margin: 0 0 8px">Account settings</p>
  <button popovertarget="menu" popovertargetaction="hide" type="button">Close</button>
</div>
Preview

Definition and usage

#

The popover attribute makes an element hidden by default and able to appear above the rest of the page. It is opened by a button with a popovertarget attribute that points to the pop-up’s id. You do not need a single line of JavaScript for it.

A pop-up with the auto value closes when you click outside it and when you press Escape, and opening another auto pop-up closes the previous one. The manual value requires closing with a button or a script.

An element with popover goes into the so-called top layer, so you do not have to fight with z-index. It is a good solution for menus, tooltips and small option panels.

Syntax

#
Syntax
<button popovertarget="popover-id">…</button>
<div id="popover-id" popover>…</div>

Values

#
  • auto

    or empty

    Closes on a click outside and on the Escape key. Opening another auto pop-up closes this one.
  • manual

    Closes only with a button or a script. Several manual pop-ups can be open at once.

Browser support

#

Newly available · since 2024

Works in the current versions of all major browsers. Older versions may not support it.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • The button that opens the pop-up sets accessibility properties on its own, for example aria-expanded.
  • For windows that block the rest of the page, such as confirmations, a <dialog> opened with the showModal() method is better.

Related entries

#

Spotted a mistake or missing an example? Write to us.