HTML popovertarget Attribute

Beginner
6 min read
Updated: Nov 2026
3 examples
Live preview

Definition and Usage

The popovertarget attribute on a <button> or certain <input> types names the id of an element that has popover. Activating the control shows, hides, or toggles that popover.

It is the declarative invoker for the Popover API. Pair it with popovertargetaction when you need explicit show or hide instead of the default toggle.

Widely available · 2024+.

Supported with the Popover API in current Chrome, Edge, Firefox, and Safari.

Target must exist and have popover.

The id must match an element with the popover attribute. A missing target does nothing useful.

HTML Syntax

syntax.html
<button|input popovertarget ="id">

Value is the id of the popover element (without #). Works on button and button-like inputs (e.g. type="button").

Attribute Values

ValueDescriptionTry it
id stringId of the popover element to controlTry it

Live Preview

Click the button to toggle a popover via popovertarget.

No JavaScript required when Popover API is supported.

Result

Controlled by popovertarget

This panel’s id is referenced by the button.

popovertarget="pt-live-panel"

HTML Examples

Example 1 — Button Targets a Popover

The simplest declarative pattern: button id reference + popover element.

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

<div id="menu" popover>
  <p>Menu content</p>
</div>
Try It Yourself

How It Works

  1. Add popover to the overlay and give it an id.
  2. Set popovertarget on the button to that id.
  3. Activate the button to toggle the popover (default action).
  4. No script is required for basic show/hide.

Example 2 — Input type=button Invoker

Button-like inputs can also invoke popovers.

HTML
<input type="button" value="Tips" popovertarget="tips">

<div id="tips" popover>
  <p>Helpful tip text.</p>
</div>
Try It Yourself

How It Works

  1. Use a button-like input such as type="button".
  2. Point popovertarget at the popover id.
  3. Prefer <button> for richer content and accessibility.
  4. Keep labels clear so users know what opens.

Example 3 — Close Control Inside Popover

Combine with popovertargetaction to add an explicit close button.

HTML
<button type="button" popovertarget="dlg">Open</button>

<div id="dlg" popover>
  <p>Content</p>
  <button type="button" popovertarget="dlg" popovertargetaction="hide">Close</button>
</div>
Try It Yourself

How It Works

  1. Open with default toggle (or action show).
  2. Add a close button with the same target id.
  3. Set action to hide so the button always closes.
  4. See popovertargetaction for show / toggle / hide details.

Edge Cases & Pitfalls

Declarative invokers are simple — id mismatches are the usual bug.

id

Id must match exactly

Typos or missing ids mean the button does nothing.

popover

Target needs popover

popovertarget only controls elements with the popover attribute.

form

Avoid submit buttons

Use type=button so the control does not submit a form.

script

Script still available

You can still call showPopover() when declarative control is not enough.

Browser Support

popovertarget is an HTML attribute for browsers. It is not a Node.js, Deno, or Bun API.

✓ Widely available · 2024+

popovertarget

Ships with the Popover API in modern Chromium, Firefox, and Safari.

92% Global support (approx.)
Google Chrome 114+
Full support
Mozilla Firefox 125+
Full support
Apple Safari 17+
Full support
Microsoft Edge 114+
Full support
Opera 100+
Full support
Samsung Internet 23+
Full support
Internet Explorer No support
Not supported
popovertarget Modern browsers

Bottom line: Use with popover for declarative overlays; feature-detect on older browsers.

Key Takeaways

  • Role: declaratively open/close a popover by id.
  • Elements: button and button-like inputs.
  • Pair with: popover on the target; optional popovertargetaction.
  • Default action: toggle unless action says otherwise.

One line: popovertarget wires a button to a popover’s id — no script required.

Frequently Asked Questions

It names the id of a popover element. Activating the button or input shows, hides, or toggles that popover.
Primarily button and button-like input types (for example type=button).
Not for basic open/close. Use popovertarget (and optional popovertargetaction) for declarative control.
Nothing useful happens. The id must match an element that has the popover attribute.
Set popovertargetaction="hide" on the close control with the same popovertarget id.
It is widely available in modern browsers with the Popover API (roughly 2024+).

Next: popovertargetaction

Choose toggle, show, or hide for popover invoker buttons.

popovertargetaction tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful