HTML popovertargetaction Attribute

Definition
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.
Syntax
HTML Syntax
<button|input popovertargetaction ="toggle|show|hide">
Requires popovertarget on the same control. Default when omitted: toggle.
Values
Attribute Values
| Value | Description | Try it |
|---|
toggle | Show if closed, hide if open (default) | Try it |
show | Always show the popover | Try it |
hide | Always hide the popover | Try it |
Try it
Live Preview
Pick an action and apply it to the invoker button.
Code
HTML Examples
Example 1 — Default Toggle Action
One button opens and closes the popover.
<button type="button" popovertarget="dock" popovertargetaction="toggle">Dock</button>
<aside id="dock" popover>Dock panel</aside>
How It Works
- Set action to toggle or omit the attribute.
- First click opens, second click closes.
- Works with auto and manual popovers.
- Ideal for a single switch control.
Example 2 — Show-Only Opener
Force the popover open without accidentally closing it on a second click.
<button type="button" popovertarget="tip" popovertargetaction="show">Show tip</button>
<div id="tip" popover>Always opens on click.</div>
Always opens on click.
How It Works
- Use show for dedicated open buttons.
- Repeated clicks stay open (already showing).
- Provide a hide control or rely on light dismiss for auto.
- Pair with hide for separate open/close UI.
Example 3 — Hide Close Button
A close button inside the popover always dismisses it.
<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>
How It Works
- Open with show (or toggle).
- Close with hide on an inner button.
- Same target id on both controls.
- Essential for manual popovers without light dismiss.
Edge Cases & Pitfalls
Wrong action values are ignored — stick to toggle, show, and hide.
defaultOmitted means toggle
You do not need to write toggle unless clarity helps.
manualManual needs an exit
Provide hide (or script) — outside clicks do not close manual popovers.
typoInvalid values
Unknown actions fall back to no useful behavior; validate spelling.
a11yLabel the intent
Button text should match show vs hide vs toggle.
Compatibility
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 supportedpopovertargetaction Modern browsers
Bottom line: Use show/hide for separate controls; toggle for a single switch.
Remember
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.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author
Developer, cloud engineer, and technical writer
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