Bootstrap 5 Tooltip

Tooltip

The tooltip component is a small popup that appears when the user moves the mouse pointer over the element:

How to create a tooltip

To create a tooltip, please set data-bs-toggle="tooltip" The attribute is added to the element.

Please use title The attribute specifies the text to be displayed in the tooltip:

<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="太棒了!">Hover over me!</button>

Note:To work, tooltips must be initialized with JavaScript.

The following code will enable all tooltips in the document:

<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
  return new bootstrap.Tooltip(tooltipTriggerEl)
)
</script>

Try It Yourself

Positioning the Tooltip

By default, the tooltip will appear at the top of the element.

Please use data-bs-placement Set the position of the tooltip on the top, bottom, left, or right of the element:

Examples

<a href="#" data-bs-toggle="tooltip" data-bs-placement="top" title="Great!">Hover</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Great!">Hover</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="left" title="Great!">Hover</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" title="Great!">Hover</a>

Try It Yourself