Course Content
Bootstrap 5 Alerts
0/1
Progress Bars
0/1
Spinners
0/1
Pagination
0/1
List Groups
0/1
Bootstrap 5 Scrollspy
0/1
Bootstrap
About Lesson

Introduction to Bootstrap 5 Tooltips

  • data-bs-toggle=”tooltip” → Enables tooltip functionality
  • title=”Tooltip Text” → Defines the tooltip content
  • data-bs-placement=”top|right|bottom|left” → Specifies tooltip position

JavaScript Code:

To Enable Tooltip Functionality in Bootstrap we need to add below JavaScript Code with each Bootstrap Tooltip Classes:

JavaScript
<!-- Enable Bootstrap 5 Tooltips -->
<script>
  document.addEventListener("DOMContentLoaded", function () {
    var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
    var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
      return new bootstrap.Tooltip(tooltipTriggerEl);
    });
  });
</script>

Bootstrap Code:

HTML
<!-- Tooltip Example -->
<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="This is a tooltip!">
  Hover over me
</button>
  • The JavaScript snippet initializes all tooltips on the page.
  • The title attribute contains the tooltip text.
  • data-bs-toggle=”tooltip” enables Bootstrap tooltip functionality.