← Back to Bootstrap Course | Chapter 8: Components — Modals & Offcanvas | Lesson 7 of 8

Tooltips

A tooltip shows a short hint when you hover or focus an element.

In this page:

  1. Tooltips
Syntax
markup
<button data-bs-toggle="tooltip" data-bs-title="Tooltip text">Hover</button>

<script>
  new bootstrap.Tooltip(element);
</script>

Tooltips

Like popovers, tooltips are opt-in and must be initialised with new bootstrap.Tooltip(element). Put the text in the title attribute or data-bs-title and choose a placement with data-bs-placement.

They appear on hover and focus, so keep them short and never hide essential information in them.

Note: Tooltips on disabled buttons need a wrapper element.

Example: Tooltips

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3">
<div class="container">
  <button type="button" class="btn btn-outline-primary" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top">Hover me</button>
  <a href="#" class="ms-3" data-bs-toggle="tooltip" data-bs-title="A helpful hint">Link with tooltip</a>
</div>
<script>
  document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach((el) => new bootstrap.Tooltip(el));
</script>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting initialisation
  2. Long tooltip text
  3. Putting essential information only in tooltips
Chapter Summary
  • Tooltips must be initialised
  • Text in title or data-bs-title
  • Hover and focus triggers
  • Keep them short
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.