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.
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));
<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>
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>
Strengthen your responsive web design mastery by studying these connected classes:
Understand how Popper.js dynamically flips tooltips and popovers.
Add helpful hover hints to icon-only action buttons.
Explain complex password requirements with interactive popovers.
Enable tooltips and popovers across your site with vanilla JavaScript.
new bootstrap.Tooltip(el) in JavaScript.
data-bs-trigger='focus' to the trigger element.
data-bs-html='true' to the element.
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