# \[popovertarget\]

> The `popovertarget` HTML attribute links a button to a popover element that it shows, hides or toggles.

## How do I open a popover with popovertarget?

The attribute of `<button>` and `<input>` elements that references the `id` of a popover element to control it. Combined with `popovertargetaction` with 'toggle', 'show' or 'hide' values, it opens and closes popovers declaratively without JS.

- Topic: Element Attributes
- Type: attribute
- Browser support: Chrome 114+, Chrome Android 114+, Edge 114+, Firefox 125+, Firefox Android 125+, Safari 17+, Safari iOS 17+

## Example

Wrong:

```html
<a href="#" popovertarget="info">Info</a>
<div id="info" popover>...</div>
```

Right:

```html
<button popovertarget="info">Info</button>
<div id="info" popover>...</div>
```

`popovertarget` only works on buttons, so the link is replaced with a `<button>`.

## Common mistakes

- Putting `popovertarget` on an `<a>` element, where it does nothing.

## Key points

- The value is the `id` of an element that has the `popover` attribute.
- `popovertarget` is on a `<button>` or `<input type='button'>`, not on a link or a `<div>`.
- `popovertargetaction` is 'toggle', 'show' or 'hide', and defaults to 'toggle'.
- No extra JS sets `aria-expanded`, the browser exposes the state itself.

## Interview questions

### How do I make a close button inside a popover?

Add a button with the same `popovertarget` and `popovertargetaction='hide'`.

### Can popovertarget open a popover without JavaScript?

Yes. The button shows, hides or toggles the popover with no script.

### What is the difference between popovertarget and commandfor?

`popovertarget` controls only popovers. `commandfor` with `command` can also open dialogs and run custom commands.

## Related cards

- [\[popover\]](https://wonderium.dev/html/popover.md)
- [.togglePopover()](https://wonderium.dev/js/toggle-popover.md)
- [\[commandfor\]](https://wonderium.dev/html/commandfor.md)
- [`<button>`](https://wonderium.dev/html/button.md)

---

- Level: [HTML](https://wonderium.dev/html.md)
- HTML version: https://wonderium.dev/html/popovertarget
- Last updated: 2026-11-25
