mc0de
mC0de / Bootstrap Elements / Lesson 04 of 07

Bootstrap Tooltips

Small hints, better experiences. Learn to add helpful hover and focus messages to buttons, links, and interface elements using Bootstrap.

Beginner Friendly Bootstrap 5.3 Interactive Hints Live Sandbox
tooltips.html
<button class="btn btn-primary"
  data-bs-toggle="tooltip"
  data-bs-title="Helpful hint!">
  Hover Me
</button>
Helpful hint! ✨
Hover Me
01 / Getting Started

What Is a Bootstrap Tooltip?

A tooltip is a short message that appears when someone hovers over or focuses on an element. It provides extra information without filling the page with additional text.

Tooltips are commonly used for icon explanations, button descriptions, shortcuts, and brief hints. Bootstrap provides the styling, positioning, and interactive behavior.

SaveShareHelp
Think of it this way: A tooltip is a helpful whisper, not an entire conversation. Keep tooltip messages short and meaningful. You’ll test real interactive tooltips in the Sandbox.
02 / The Basics

Create Your First Tooltip

Start with an ordinary Bootstrap button. Add data-bs-toggle="tooltip" to identify the element as a tooltip trigger, and data-bs-title to supply its message.

<button type="button"
  class="btn btn-primary"
  data-bs-toggle="tooltip"
  data-bs-title="Click to save your changes">
  Save
</button>
data-bs-toggle="tooltip" Marks the element as a Bootstrap tooltip trigger.
data-bs-title Supplies the text displayed inside the tooltip.

Unlike Bootstrap dropdowns, tooltips are not activated automatically just by adding HTML attributes. They must be initialized with JavaScript.

03 / JavaScript Initialization

Make Your Tooltips Work

First, include Bootstrap’s CSS and JavaScript bundle. Then initialize every element marked as a tooltip. The bundle includes Popper, which Bootstrap uses for tooltip positioning.

<link rel="stylesheet"
  href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

<script>
  const triggers =
    document.querySelectorAll('[data-bs-toggle="tooltip"]');

  triggers.forEach(element => {
    new bootstrap.Tooltip(element);
  });
</script>
Important: Run the initialization after the tooltip elements and Bootstrap JavaScript have loaded. Our interactive Sandbox takes care of this automatically for you.
04 / Placement

Choose Where the Tooltip Appears

Bootstrap supports four tooltip placements: top, bottom, start, and end. Use data-bs-placement to select one.

topDisplays the tooltip above its trigger.
bottomDisplays the tooltip below its trigger.
startDisplays the tooltip on the starting side.
endDisplays the tooltip on the ending side.
<button type="button"
  class="btn btn-success"
  data-bs-toggle="tooltip"
  data-bs-placement="bottom"
  data-bs-title="This appears below the button">
  Bottom Tooltip
</button>

Bootstrap may adjust a tooltip’s placement when there isn’t enough space, helping prevent it from being cut off by the viewport.

05 / Custom Messages

Write Helpful Tooltip Text

A tooltip should explain an action or provide useful context. For example, a button labeled “Export” might display a message explaining the file format.

<button type="button"
  class="btn btn-outline-primary"
  data-bs-toggle="tooltip"
  data-bs-title="Download your report as a PDF">
  Export
</button>

Prefer clear, concise text. Avoid placing important instructions or essential information only inside tooltips, because not every user can easily discover or interact with them.

06 / Accessibility

Support Keyboard and Touch Users

Bootstrap tooltips can appear when a user focuses on a button or link using the keyboard. This is why it’s important to use accessible, focusable elements as triggers.

<button type="button"
  class="btn btn-secondary"
  data-bs-toggle="tooltip"
  data-bs-trigger="hover focus"
  data-bs-title="Open your account settings">
  Settings
</button>
Accessibility tip: Don’t rely on hover alone. Touchscreens don’t have traditional mouse hover, and disabled buttons cannot receive normal keyboard focus. If an explanation is essential, display it directly on the page.
07 / Advanced Options

Control How Tooltips Behave

Bootstrap also supports options such as data-bs-trigger and data-bs-custom-class. These allow you to change when tooltips appear and customize their visual appearance.

<button type="button"
  class="btn btn-dark"
  data-bs-toggle="tooltip"
  data-bs-trigger="click"
  data-bs-title="Click again to hide this hint">
  Click for Hint
</button>

The click trigger can be useful when a tooltip needs to appear after a deliberate action. For ordinary explanatory hints, hover and focus behavior is generally more familiar.

Your Turn / Practice Time

🚀 mC0de Challenge

Build a Helpful Action Toolbar

Imagine you’re building a document editor. Your toolbar has several buttons, and you want to help users understand what each action does.

Your mission: Complete all five tasks in the Sandbox below.

Check off each task as you finish. You can load the sample solution to compare your results.

Interactive Coding Workspace

mC0de Bootstrap Sandbox

Edit the HTML, run your code, and hover over or focus on the buttons to reveal tooltips.

HTML Input / tooltips.html
Live Result / Bootstrap 5.3
Ready to code. Tooltips are initialized automatically inside the preview.
Lesson Recap

✓ What You've Learned

  • Tooltips display short contextual messages when users interact with an element.
  • data-bs-toggle="tooltip" identifies a Bootstrap tooltip trigger.
  • data-bs-title defines the tooltip message.
  • Tooltips must be initialized using Bootstrap JavaScript.
  • data-bs-placement controls top, bottom, start, or end positioning.
  • data-bs-trigger controls how a tooltip is activated.
  • Focusable buttons and links make tooltip interaction more accessible.
  • Tooltips should provide supplementary hints, not essential instructions.

Up next: We'll explore Bootstrap List Design and learn to create attractive, structured list groups.

Your Learning Journey
Bootstrap Elements Learning Path 0 of 7 completed
Lesson 04 / Tooltips 0% Complete

Nice Work! 🎉

You've learned how to create Bootstrap tooltips, customize their messages and positions, and make helpful hints available through keyboard focus. Ready to record your progress?

Lesson 04 of 07 · Bootstrap Elements