VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-modal-tooltips-and-popovers/

⇱ Bootstrap 5 Modal Tooltips and Popovers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Modal Tooltips and Popovers

Last Updated : 23 Jul, 2025

Bootstrap 5 provides a robust way to enhance user interfaces through modals, tooltips, and popovers. These components help in displaying additional information to users without cluttering the main content. Tooltips offer brief descriptions, while popovers can contain more detailed information. Both are highly useful in guiding users through the modal's content efficiently. 

When a modal is opened, any tooltips and popovers initialized within it are dynamically attached to provide contextual help. Once the modal is closed, Bootstrap automatically handles the cleanup by closing any visible tooltips and popovers. This ensures a clean and seamless user experience without leaving behind any open elements, which could potentially confuse users.

Bootstrap 5 Modal Tooltips and popovers Classes: There are no specific classes for using the tooltips and popovers inside the Modal. It uses a combination of data attributes and JavaScript to trigger these features. By adding `data-bs-toggle="tooltip"` or `data-bs-toggle="popover"` to an element, you can easily enable these interactive components within a modal.

Syntax:

<!-- Modal Structure -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal Title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<!-- Modal Body -->
<div class="modal-body">
<!-- Button with Tooltip -->
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="Tooltip Text Here">
Hover the Button
</button>
</div>
<!-- Modal Footer -->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>

Example 1: The below example illustrates the use of the tooltips inside the modal component.

Output:

Example 2: In this example, we used both the tooltip and the popover inside our bootstrap 5 modal.

Output:

Tooltips and popovers are valuable additions to Bootstrap 5 modals, offering users helpful information without cluttering the interface. By using Bootstrap's data attributes and JavaScript, you can easily implement these features to create a more interactive and user-friendly experience. Ensure accessibility and thoughtful placement for optimal usability.

Reference: https://getbootstrap.com/docs/5.2/components/modal/#tooltips-and-popovers

Comment

Explore