Bootstrap

Bootstrap Tooltip

Bootstrap Tooltips: Enhance UX with Hover Text

Ever hovered over a button and seen a helpful label pop up? That’s a tooltip — a tiny, unobtrusive UX upgrade that improves clarity and usability. Bootstrap’s built-in tooltip component makes adding these little helpers simple and effective.

In this article, we’ll show you how to use Bootstrap Tooltips to provide instant feedback, context, and guidance without cluttering your UI.


What is a Tooltip?

A tooltip is a small pop-up box that appears when a user hovers (or focuses) over an element. It’s often used to:

  • Label icons or buttons

  • Explain form inputs

  • Provide hints for abbreviations or terms

Bootstrap uses Popper.js under the hood to position tooltips automatically.


Basic Tooltip Example

Here’s a simple tooltip on a button:

html
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">
Hover me
</button>

To activate tooltips, initialize them using JavaScript:

js
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))

⚠️ Tooltips must be initialized via JavaScript — they don’t work automatically.


Placement Options

You can position tooltips on all four sides of an element:

html
data-bs-placement="top" | "right" | "bottom" | "left"

Example:

html
<button data-bs-toggle="tooltip" data-bs-placement="right" title="Tooltip on right">Right</button>

✨ Advanced Features

1. Trigger Options

Control how tooltips show up:

html
data-bs-trigger="hover focus" <!-- Default -->
data-bs-trigger="click"
data-bs-trigger="manual"

Leave a Reply

Your email address will not be published. Required fields are marked *