← Back to Bootstrap Course | Chapter 8: Components — Modals & Offcanvas | Lesson 6 of 8

Popovers

A popover shows a small floating box with a title and content when an element is clicked.

In this page:

  1. Popovers
Syntax
markup
<button data-bs-toggle="popover" data-bs-title="Title" data-bs-content="Content">Click</button>

<script>
  new bootstrap.Popover(element);
</script>

Popovers

Popovers are opt-in: initialise them in JavaScript with new bootstrap.Popover(element), and set data-bs-toggle="popover", data-bs-title and data-bs-content on the trigger.

Placement is chosen with data-bs-placement. They use Popper for positioning and are triggered by click by default.

Note: Popovers and tooltips must be initialised manually for performance reasons.

Example: Popovers

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3">
<div class="container">
  <button type="button" class="btn btn-secondary" data-bs-toggle="popover" data-bs-title="Popover title" data-bs-content="And here is some amazing content." data-bs-placement="right">Click for popover</button>
</div>
<script>
  document.querySelectorAll('[data-bs-toggle="popover"]').forEach((el) => new bootstrap.Popover(el));
</script>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting to initialise them
  2. Using them on disabled elements
  3. Hiding critical info in popovers
Chapter Summary
  • Popovers must be initialised
  • data-bs-title and data-bs-content
  • data-bs-placement positions
  • Click trigger by default
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.