Introduction
Tooltips show helpful text when you hover or focus on an element. They guide users without cluttering the page.
Tooltips show helpful text when you hover or focus on an element. They guide users without cluttering the page.
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip text">Hover me</button> <script> var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }) </script>
data-bs-toggle="tooltip" to mark elements that show tooltips.<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" data-bs-placement="right" title="Tooltip on right">Right Tooltip</button>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Tooltip at bottom">Bottom Tooltip Link</a>
<span data-bs-toggle="tooltip" data-bs-placement="left" title="Tooltip on left">Hover over me</span>
This page shows a blue button. When you move your mouse over it, a small box with the text "This is a tooltip!" appears above the button.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Tooltip Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="p-4"> <button type="button" class="btn btn-info" data-bs-toggle="tooltip" data-bs-placement="top" title="This is a tooltip!"> Hover over me </button> </main> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script> const tooltipTriggerList = Array.from(document.querySelectorAll('[data-bs-toggle="tooltip"]')) tooltipTriggerList.forEach(tooltipTriggerEl => { new bootstrap.Tooltip(tooltipTriggerEl) }) </script> </body> </html>
Tooltips only appear on hover or keyboard focus for accessibility.
Always provide clear and short tooltip text to help users quickly.
Remember to include Bootstrap's CSS and JS files for tooltips to work.
Tooltips show extra info when hovering or focusing on elements.
Use data-bs-toggle="tooltip" and initialize with JavaScript.
They improve user experience by giving hints without clutter.
data-bs-toggle="tooltip" on the element.<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" title="Save changes">Save</button>
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>data-bs-toggle="tooltip" and a title attribute. The script initializes Bootstrap tooltips on all such elements.<button type="button" class="btn btn-primary" data-toggle="tooltip" title="Click me">Click</button>
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (el) {
return new bootstrap.Tooltip(el);
});
</script>data-toggle="tooltip" but Bootstrap 5 requires data-bs-toggle="tooltip".data-bs-toggle="tooltip", so it finds none because the button uses the old attribute.data-bs-toggle="tooltip" and a title attribute for text. They show on hover and keyboard focus.aria-label only without JavaScript lacks tooltip behavior, C uses popover (different), D shows text always (not tooltip).Pass the test and this pattern moves unknown