Class 32 of 48 • Interactive JavaScript

Bootstrap 5 Tooltips & Popovers: Popper.js Positioning & Events

Tooltips and Popovers are lightweight contextual floating bubbles powered by Popper.js. For performance reasons, both components are opt-in: you must initialize them via JavaScript before they will appear on hover or click.

Bootstrap 5 Opt-in Tooltips and Rich Popovers with Popper.js
Figure 32: Dynamic floating tips powered by Popper.js showing directional triggers (top, right, bottom, left) and rich headers.

1. Initializing All Tooltips via JavaScript

Add this one-liner script at the bottom of your webpage before </body>:

// Initialize all elements with data-bs-toggle="tooltip"
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
const tooltipList = [...tooltipTriggerList].map(el => new bootstrap.Tooltip(el));

2. Tooltip Directions (Top, Bottom, Left, Right)

<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top">Top</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Tooltip on bottom">Bottom</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="Tooltip on left">Left</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="Tooltip on right">Right</button>

3. Interactive Popovers

Popovers offer more space than tooltips, supporting titles, multi-line descriptions, and HTML markup:

<button type="button" class="btn btn-danger" data-bs-toggle="popover" data-bs-title="Database Alert" data-bs-content="All lab database records are archived nightly at 2:00 AM.">
  Click for Popover Notice
</button>

<script>
  // Initialize popovers
  const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]');
  const popoverList = [...popoverTriggerList].map(el => new bootstrap.Popover(el));
</script>

Explore Related Bootstrap Tutorials & Next Steps

Strengthen your responsive web design mastery by studying these connected classes:

Popper.js Engine Positioning

Understand how Popper.js dynamically flips tooltips and popovers.

Buttons with Interactive Tooltips

Add helpful hover hints to icon-only action buttons.

Form Field Hints via Popovers

Explain complex password requirements with interactive popovers.

Initializing Tooltips in JS

Enable tooltips and popovers across your site with vanilla JavaScript.

Frequently Asked Questions (FAQ) - Student & Interview Review

They are opt-in for performance reasons! You must initialize them using new bootstrap.Tooltip(el) in JavaScript.
Add data-bs-trigger='focus' to the trigger element.
Yes! Add data-bs-html='true' to the element.

Next Step in Your Bootstrap Learning Path:

Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.

Continue to Class 33: Toasts Notifications → Previous: ← Class 31: Carousel Sliders | Full Syllabus

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!