webdevpuneet.com

Bootstrap Tooltip Showcase — Free Snippet

Bootstrap Tooltip Showcase · Modals · Plain HTML, CSS & JS · Live preview

CategoryModals

Copy & paste

Source Code

<div class="container py-5 text-center">
  <h1 class="bstip-title">Hover any button</h1>
  <p class="text-muted small mb-4">Real Bootstrap tooltips, initialized once in JavaScript from a data attribute.</p>
  <div class="d-flex flex-wrap gap-3 justify-content-center">
    <button class="btn btn-dark" data-bs-toggle="tooltip" data-bs-placement="top" title="Appears above">Top</button>
    <button class="btn btn-dark" data-bs-toggle="tooltip" data-bs-placement="right" title="Appears to the right">Right</button>
    <button class="btn btn-dark" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Appears below">Bottom</button>
    <button class="btn btn-dark" data-bs-toggle="tooltip" data-bs-placement="left" title="Appears to the left">Left</button>
    <button class="btn btn-outline-dark" data-bs-toggle="tooltip" data-bs-html="true" title="<strong>Bold</strong> HTML content">HTML content</button>
    <button class="btn btn-primary" data-bs-toggle="tooltip" title="Click me to save your changes">Save</button>
  </div>
  <p class="text-muted small mt-4">Tooltips initialized: <strong id="bstipCount">0</strong></p>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Real Bootstrap 5.3 Tooltip component, explicitly initialized — the correct, required pattern
All four cardinal placements demonstrated: top, right, bottom, left
HTML-content tooltip shown correctly via the required data-bs-html="true" opt-in
A live count confirms exactly how many tooltip instances were created
Query-all-and-map pattern scales to any number of tooltip triggers on a page
No custom tooltip library — this is Bootstrap's own Popper-powered component

About this UI Snippet

Bootstrap Tooltip Showcase — HTML, CSS & JavaScript

Screenshot of the Bootstrap Tooltip Showcase snippet rendered live

Most Bootstrap components — Modal, Collapse, Dropdown, Tab — wire themselves up automatically the instant bootstrap.bundle.min.js loads, just from their data-bs-toggle attribute. Tooltip is the one common exception. This snippet shows the full, correct pattern: every element carrying data-bs-toggle="tooltip" still needs an explicit new bootstrap.Tooltip(el) call before it will ever show up, which is the single most common "why doesn't this tooltip work" mistake in real Bootstrap projects.

The six examples cover every cardinal placement (data-bs-placement), a tooltip rendering HTML content via data-bs-html="true" — which requires explicitly opting in, since raw HTML in a tooltip is disabled by default as an XSS precaution — and a tooltip on a primary action button, the most common real-world placement.

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The preview loads six buttons and a count of initialized tooltips.
  2. 2
    Hover each buttonEach shows Bootstrap's real tooltip in a different placement — top, right, bottom, left.
  3. 3
    Hover "HTML content"Its tooltip renders the bold text as actual formatting, not escaped text, because of data-bs-html="true".
  4. 4
    Add a tooltip to your own buttonAdd data-bs-toggle="tooltip" and a title attribute to any element, then add it to the JS panel's querySelectorAll selector — or just re-query on load, which already includes it.

Real-world uses

Common Use Cases

Learning why your Bootstrap tooltips don't appear
The single most common Bootstrap support question — forgetting the explicit new bootstrap.Tooltip() initialization — solved and demonstrated directly.
Icon-only buttons needing a text label
A tooltip is the standard way to give an icon-only button (like an admin panel's action icons) an accessible, visible label on hover.
Form fields with inline help text
Attach a tooltip to a form label or a small info icon next to a field for contextual help without cluttering the layout.
Any UI needing consistent hover explanations
Reuse the query-all-and-initialize pattern anywhere multiple tooltip triggers exist on one page.

Got questions?

Frequently Asked Questions

Bootstrap's Modal, Collapse, Dropdown, and Tab components self-initialize from their data-bs-toggle attribute alone. Tooltip and Popover are the exceptions — the library requires an explicit new bootstrap.Tooltip(element) call per element, by design, since auto-initializing every tooltip on a page could be expensive on content-heavy pages.

Add data-bs-html="true" to the trigger element. Without it, Bootstrap escapes the title content as plain text for security, so any markup would show as literal angle brackets instead of rendering.

Yes — pass a delay option to the constructor, e.g. new bootstrap.Tooltip(el, { delay: { show: 300, hide: 100 } }), instead of the default near-instant show.

Bootstrap tooltips trigger on hover and focus by default, which touch devices approximate via tap-and-hold or focus in some browsers, but the experience is less consistent than on desktop — consider a different pattern (like a Popover on click) for primarily touch-driven interfaces.

Bootstrap renders it as escaped, literal text — you would see the actual angle brackets and tag names in the tooltip instead of formatted content, which is a safe default rather than a silent failure.