Skip to main content
← πŸ“„ HTML & the platformΒ·Module A7 Β· Lesson 9
TaskBuild a popover. <button popovertarget='info'>Info</button> + <div id='info' popover><p>Hello</p></div>.

Native popover API

100 XP7 min
Theory

Tooltips, menus, and disclosures β€” no JS

Shipped 2024 across Chrome / Safari / Firefox:

<button popovertarget="my-popover">Open</button>

<div id="my-popover" popover>
  <p>This is a popover.</p>
  <button popovertarget="my-popover" popovertargetaction="hide">Close</button>
</div>

Click the button β†’ popover opens. Click outside or press ESC β†’ it closes. The button gets aria-expanded updated automatically. Free.

popover values

  • popover or popover="auto" β€” light-dismiss (click outside closes).
  • popover="manual" β€” only closes when explicitly told. Use for persistent toasts.

Positioning with anchor-positioning

Pair with the CSS anchor-positioning API to position the popover relative to its trigger:

#my-popover {
  position-anchor: --my-button;
  inset-area: bottom span-right;
}
#my-button { anchor-name: --my-button; }

(Anchor positioning is a 2024+ feature with patchier support; use feature detection.)

When to use popover vs dialog

  • `<dialog>` β€” modal. Backdrop dims the page. Focus is trapped inside.
  • `popover` β€” non-modal. Page stays interactive. Multiple popovers can coexist.

Tooltips, dropdown menus, hover cards β†’ popover. Cookie consent, modal forms β†’ dialog.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 10 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.