# Popover

> A popover is a small overlay with a title and a body, for information that doesn't fit in a tooltip.

Show extra information in popovers when a tooltip is not enough. Set the placement and trigger to control how they appear.

Source: https://docs.tabler.io/ui/components/popover

---

## Default markup

To create a default popover use:

```html
<button type="button" class="btn" data-bs-toggle="popover" title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?"> Click to toggle popover </button>
```

## Four directions

Four options are available: `top`, `right`, `bottom`, and `left` aligned. Directions are mirrored when using Bootstrap in [RTL](/ui/getting-started/rtl).

```html
<div class="btn-list">
  <button type="button" class="btn" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="top" data-bs-content="Top popover"> Popover on top </button>
  <button type="button" class="btn" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="right" data-bs-content="Right popover"> Popover on right </button>
  <button type="button" class="btn" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="bottom" data-bs-content="Bottom popover"> Popover on bottom </button>
  <button type="button" class="btn" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="left" data-bs-content="Left popover"> Popover on left </button>
</div>
```

## Popover on hover

A popover can open on `click`, `hover`, `focus` or `manual`, set with `data-bs-trigger`. This one opens on hover. See the [Bootstrap documentation](https://getbootstrap.com/docs) for the details.

```html
<button type="button" class="btn btn-primary" data-bs-trigger="hover" data-bs-toggle="popover" title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?"> Hover to toggle popover </button>
```

## JavaScript

Tabler automatically initializes all elements with `data-bs-toggle="popover"` on page load. This is the code that runs:

```ts
onDOMContentLoaded(() => {
  for (const popoverTriggerEl of document.querySelectorAll<HTMLElement>('[data-bs-toggle="popover"], [data-tblr-toggle="popover"]')) {
    try {
      const options = {
        delay: Manipulator.getDataAttribute(popoverTriggerEl, 'delay') ?? { show: 50, hide: 50 },
        placement: Manipulator.getDataAttribute(popoverTriggerEl, 'placement') ?? 'auto',
      }
      Popover.getOrCreateInstance(popoverTriggerEl, options)
    } catch (error) {
      console.error(error)
    }
  }
})
```

_Source: `core/js/src/popover.ts`_

To use your own options, create the instance yourself. It replaces the one Tabler created, so only your options apply:

```js
const el = document.getElementById('my-popover');
new tabler.Popover(el, { customClass: 'popover-wide', trigger: 'focus' });
```

To read or control the existing instance without changing its options, use `tabler.Popover.getInstance(el)` or `tabler.Popover.getOrCreateInstance(el)`.

## Accessibility

- The trigger must be a `button` or a link with an `href`, so it can take focus. Bootstrap manages `aria-describedby` while the popover is open.
- Popovers open on click by default, which is what makes their content reachable. If you switch to `data-bs-trigger="hover"`, the content becomes unreachable by keyboard.
- Set `data-bs-trigger="focus"` to make a popover dismiss itself when focus leaves, which is the closest thing to <kbd>Escape</kbd> behavior.
- Tabler enables HTML in a popover only when you set `data-bs-html="true"`. Leave it off for content that comes from users.
- Keep the title and body as text. A popover holding a form is a modal in disguise - use a real dialog for that.
