HTML popovertargetaction Attribute

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

Definition and Usage

The popovertargetaction attribute tells a popovertarget control what to do: toggle (default), show, or hide the referenced popover.

Use show for open-only buttons, hide for close controls inside the popover, and omit or use toggle for a single open/close switch.

Default is toggle.

If you omit popovertargetaction, activating the control toggles the popover.

Needs popovertarget.

popovertargetaction has no effect without a matching popovertarget id.

HTML Syntax

syntax.html
<button|input popovertargetaction ="toggle|show|hide">

Requires popovertarget on the same control. Default when omitted: toggle.

Attribute Values

ValueDescriptionTry it
toggleShow if closed, hide if open (default)Try it
showAlways show the popoverTry it
hideAlways hide the popoverTry it

Live Preview

Pick an action and apply it to the invoker button.

Change the action, then click Activate. Use hide after the panel is open.

Result

Action demo

Try show, hide, and toggle.

popovertargetaction="toggle"

HTML Examples

Example 1 — Default Toggle Action

One button opens and closes the popover.

HTML
<button type="button" popovertarget="dock" popovertargetaction="toggle">Dock</button>

<aside id="dock" popover>Dock panel</aside>
Try It Yourself

How It Works

  1. Set action to toggle or omit the attribute.
  2. First click opens, second click closes.
  3. Works with auto and manual popovers.
  4. Ideal for a single switch control.

Example 2 — Show-Only Opener

Force the popover open without accidentally closing it on a second click.

HTML
<button type="button" popovertarget="tip" popovertargetaction="show">Show tip</button>

<div id="tip" popover>Always opens on click.</div>
Try It Yourself

How It Works

  1. Use show for dedicated open buttons.
  2. Repeated clicks stay open (already showing).
  3. Provide a hide control or rely on light dismiss for auto.
  4. Pair with hide for separate open/close UI.

Example 3 — Hide Close Button

A close button inside the popover always dismisses it.

HTML
<button type="button" popovertarget="box" popovertargetaction="show">Open</button>

<div id="box" popover>
  <p>Closeable panel</p>
  <button type="button" popovertarget="box" popovertargetaction="hide">Close</button>
</div>
Try It Yourself

How It Works

  1. Open with show (or toggle).
  2. Close with hide on an inner button.
  3. Same target id on both controls.
  4. Essential for manual popovers without light dismiss.

Edge Cases & Pitfalls

Wrong action values are ignored — stick to toggle, show, and hide.

default

Omitted means toggle

You do not need to write toggle unless clarity helps.

manual

Manual needs an exit

Provide hide (or script) — outside clicks do not close manual popovers.

typo

Invalid values

Unknown actions fall back to no useful behavior; validate spelling.

a11y

Label the intent

Button text should match show vs hide vs toggle.

Browser Support

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

✓ Widely available · 2024+

popovertargetaction

Available wherever popovertarget and the Popover API are supported.

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
popovertargetaction Modern browsers

Bottom line: Use show/hide for separate controls; toggle for a single switch.

Key Takeaways

  • Values: toggle (default), show, hide.
  • Requires: popovertarget on the same element.
  • Close UI: hide inside the popover for manual panels.
  • Open UI: show when you never want a second click to close.

One line: popovertargetaction chooses toggle, show, or hide for the invoker.

Frequently Asked Questions

toggle (default), show, and hide.
If omitted, the action is toggle — open when closed, close when open.
When the button should only open the popover, never close it on a second click.
For close buttons inside the popover, especially with popover=manual.
No. popovertargetaction requires popovertarget on the same control.
Yes — it ships with the Popover API in modern browsers.

Next: poster

Show an image on a video before playback starts.

poster 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