Menu

Bootstrap 5 Tooltip


Previous


Next

Tooltips

The Tooltip component is small pop-up box that appears when the user moves the mouse pointer over an element:

How To Create a Tooltip

To create a tooltip, add the data-bs-toggle="tooltip" attribute to an element.

Use the title attribute to specify the text that should be displayed inside the tooltip:

<button type=”button” class=”btn btn-primary” data-bs-toggle=”tooltip” title=”Hooray!”>Hover over me!</button>

Note: Tooltips must be initialized with JavaScript to work.  The following code will enable all tooltips in the document:

Example

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>

<div>
<h3>Tooltip Example</h3>

<button type=”button” data-bs-toggle=”tooltip” title=”Hooray!”>
Hover over me!
</button>
</div>

<script>
// Initialize tooltips
var tooltipTriggerList = [].slice.call(document.querySelectorAll(‘[data-bs-toggle=”tooltip”]’))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl)
})
</script>

</body>
</html>

Positioning Tooltips

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

Use the data-bs-placement attribute to set the position of the tooltip on top, bottom, left or the right side of the element:

Example

<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>

<div>
<h3>Tooltip Positioning</h3>
<p>The data-bs-placement attribute specifies the tooltip position.</p>
<a href=”#” data-bs-toggle=”tooltip” data-bs-placement=”top” title=”Hooray!”>Top</a>
<a href=”#” data-bs-toggle=”tooltip” data-bs-placement=”bottom” title=”Hooray!”>Bottom</a>
<a href=”#” data-bs-toggle=”tooltip” data-bs-placement=”left” title=”Hooray!”>Left</a>
<a href=”#” data-bs-toggle=”tooltip” data-bs-placement=”right” title=”Hooray!”>Right</a>
</div>

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

</body>
</html>


Previous


Next

Scroll to Top