DevTools Logo

Popover API Playground

Popover API Playground

Build native popovers and copy the exact HTML, CSS and JS.

Runs in your browser
Try an example

Input

1 line · 13 chars

Result

24 lines · 570 chars

The Popover API Playground renders real popovers from the attributes you configure — no simulations. Toggle auto versus manual to see light dismiss, choose a popovertarget trigger or a showPopover() call, style the ::backdrop, add a nested child popover, and copy HTML, CSS and JS that mirror exactly what the stage shows. The event log records toggle transitions so the difference between opening, closing and idempotent actions is visible.

Examples

Input
mode=auto, trigger=toggle
Output
<button popovertarget="demo">Toggle</button>
<div id="demo" popover="auto">Content</div>

The declarative form is the shortest working auto popover.

Input
mode=manual, trigger=js
Output
document.getElementById("demo").togglePopover()

Manual popovers need an explicit call since light dismiss does not close them.

Input
backdrop blur=4px
Output
#demo::backdrop { backdrop-filter: blur(4px); }

Backdrop effects appear only while the popover is shown.

About this tool

This playground is a hands-on reference for the native Popover API. Every control maps to a real attribute or CSS rule, and the code panes are generated from the same configuration that renders the stage, so what you copy is what you saw.

Use it to understand auto versus manual behavior: auto popovers support light dismiss and Escape, only one sibling auto popover is open at a time, and closing a parent closes its nested auto children. Manual popovers stay open until an explicit action closes them.

User content is inserted as text, never as innerHTML, so pasted markup cannot execute scripts. The tool runs entirely in your browser.

What this tool does not do

  • Older browsers without the Popover API show a support banner; generated code still copies but the stage degrades gracefully.
  • CSS anchor positioning is not implemented; the popover uses fixed placement presets.
  • jsdom does not implement the top layer or popover events, so toggle logging is verified in a real browser rather than unit tests.

How to use this tool

  1. Choose the mode

    Select auto or manual. Auto supports light dismiss and Escape; manual requires an explicit hide action.

  2. Configure the trigger

    Use a popovertarget button with show, hide or toggle action, or choose the JS trigger mode to get a showPopover() call.

  3. Style and nest

    Set backdrop color, blur and transition, and optionally add a nested child popover to see native stacking.

  4. Copy the code

    Switch between the HTML, CSS and JS tabs and copy each snippet. The JS tab is emitted only for JS trigger mode.

Use cases

Replace a tooltip library

Prototype a native, accessible tooltip with no dependency, then copy the minimal markup and CSS into your app.

Teach the platform

Demonstrate light dismiss, nesting and the toggle event live in a workshop without building a demo app.

Design-system primitives

Compare auto and manual semantics before baking a popover component into your design system.

Attribute reference

Attribute / APIValues
popoverauto | manual
popovertargetelement id
popovertargetactionshow | hide | toggle
::backdropCSS
toggle eventoldState / newState

The JS tab is generated only when the JS trigger mode is selected; declarative mode needs no script at all.

Common mistakes

Mistake:Expecting manual popovers to close on outside click.

Fix:That is correct auto behavior only. Manual popovers ignore light dismiss and Escape; call hidePopover() or use a hide trigger.

Mistake:Using popover where a modal dialog is needed.

Fix:Popovers are non-modal by default and do not trap focus or make the rest of the page inert. Use the dialog element for modals.

Mistake:Assuming close transitions work with display alone.

Fix:Closing exit animations need transition-behavior: allow-discrete on overlay and display, plus @starting-style for the opening state.

Frequently asked questions

What is the difference between popover auto and manual?

An auto popover supports light dismiss: clicking outside it or pressing Escape closes it, and opening another auto popover closes the first. A manual popover ignores both and stays open until your code hides it or a hide trigger is used. Auto also closes nested auto children when the parent closes.

Does popover replace dialog?

No. A popover is non-modal by default: the rest of the page stays interactive and focus is not trapped. Use the dialog element with showModal() when you need a modal that makes the rest of the page inert and traps focus.

How does light dismiss work?

In auto mode the browser closes the popover when you click or focus outside it, or press Escape. The toggle event fires with oldState and newState so you can react. Manual mode deliberately does not light-dismiss.

Can popovers nest?

Yes. A popover inside another popover opens above it in the top layer. With auto mode, closing the parent also closes its nested auto children; with manual mode you must close them yourself.

How do I style the backdrop?

Use the ::backdrop pseudo-element on the popover, for example #p::backdrop { background: rgba(0,0,0,.45); backdrop-filter: blur(3px); }. It applies only while the popover is shown. Smooth open and close transitions additionally need @starting-style and allow-discrete on display and overlay.

References & standards