Skip to main content

Components

Tooltips

Hover and focus hints rendered from an attribute by CSS pseudo-elements.

How it works

Add data-bs-toggle="tooltip" and data-bs-title="…" to any element. The CSS draws the bubble with ::after (its text is attr(data-bs-title)) and the arrow with ::before. Both appear on :hover and :focus-visible. No element is inserted, no script runs.

  • Baseline: absolutely positioned pseudo-elements on the trigger. Works everywhere, but an overflow: hidden ancestor clips the bubble.
  • Enhancement: CSS anchor positioning moves the bubble to position: fixed with position-area, so it escapes clipping and flips to the opposite side when there is no room.
  • Fallback: none needed — the baseline is the fallback.
data-bs-toggle="tooltip", data-bs-title and data-bs-placement are the only data-bs-* attributes this theme's CSS reads. data-bs-html, data-bs-custom-class and data-bs-trigger do nothing.

Examples

Hover or tab to the buttons. data-bs-placement takes top (default), bottom, start or end.

HTML
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top">Tooltip on top</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="end" data-bs-title="Tooltip on end">Tooltip on end</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Tooltip on bottom">Tooltip on bottom</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="start" data-bs-title="Tooltip on start">Tooltip on start</button>

Omit data-bs-placement for the default, top.

HTML
<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" data-bs-title="Default tooltip">Default placement</button>

Inline links work the same way. The trigger gets position: relative, which is harmless on inline elements.

Tight pants, big belts, and fireworks. The crowd noise on this clip is real.

HTML
<p class="mb-0">
  Tight pants, <a href="#!" data-bs-toggle="tooltip" data-bs-title="Default tooltip">big belts</a>, and
  <a href="#!" data-bs-toggle="tooltip" data-bs-title="Another tooltip">fireworks</a>. The
  <a href="#!" data-bs-toggle="tooltip" data-bs-title="Another one here too">crowd noise</a> on this
  <a href="#!" data-bs-toggle="tooltip" data-bs-title="The last tip!">clip</a> is real.
</p>

Text only

The bubble content comes from attr(), which returns a plain string. HTML in data-bs-title is shown as literal characters, and the text is centered and wraps at --bs-tooltip-max-width (200px). Line breaks are not possible. For rich content use a popover.

HTML
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-title="A longer tooltip that wraps onto a second line when it hits the max width.">Long tooltip</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-title="&lt;em&gt;Tags&lt;/em&gt; are literal">HTML is literal</button>

Disabled elements

Disabled elements do not fire hover or focus, and a disabled button has pointer-events: none. Wrap it in a <span tabindex="0"> and put the tooltip attributes on the span. The span receives the hover that passes through the button and can take keyboard focus.

HTML
<span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-title="Suspended for 30 days">
  <button class="btn btn-primary" type="button" disabled>Book this wrestler</button>
</span>

Escaping overflow

The box below has overflow: hidden. In engines with CSS anchor positioning the tooltip is rendered fixed and anchored, so it shows in full above the box. In older engines it is clipped by the box — still legible on hover inside it, just not outside.

HTML
<div class="overflow-hidden border rounded p-4">
  <button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-title="Anchored tooltips escape the clipping box">Hover me — I'm in an overflow: hidden box</button>
</div>

Accessibility

  • Only put tooltips on elements that can take focus: buttons, links, inputs. Add tabindex="0" to anything else.
  • The tooltip is generated content, which most screen readers do not announce. Use aria-label or aria-describedby on the trigger to carry the same text — or make sure the visible label already says it.
  • The bubble is pointer-events: none; it never blocks a click.
  • The opacity transition respects prefers-reduced-motion.
  • Colours are --bs-emphasis-color on --bs-body-bg, so dark mode inverts the bubble automatically.

CSS

The variables are set on the trigger, [data-bs-toggle="tooltip"], rather than on a .tooltip element. Override them inline or on a wrapper.

[data-bs-toggle="tooltip"] {
  --bs-tooltip-zindex: 220;
  --bs-tooltip-max-width: 200px;
  --bs-tooltip-padding-x: 0.5rem;
  --bs-tooltip-padding-y: 0.25rem;
  --bs-tooltip-font-size: 0.875rem;
  --bs-tooltip-color: var(--bs-body-bg);
  --bs-tooltip-bg: var(--bs-emphasis-color);
  --bs-tooltip-border-radius: 2px;
  --bs-tooltip-opacity: 1;
  --bs-tooltip-arrow-width: 0.8rem;
  --bs-tooltip-arrow-height: 0.4rem;
}
HTML
<button type="button" class="btn btn-outline-primary" data-bs-toggle="tooltip" data-bs-title="Gold on navy" style="--bs-tooltip-bg: var(--bs-navy); --bs-tooltip-color: var(--bs-gold); --bs-tooltip-max-width: 120px;">Custom tooltip</button>

Behavioural selectors:

[data-bs-toggle="tooltip"]::after          // bubble: content: attr(data-bs-title)
[data-bs-toggle="tooltip"]::before         // arrow
[data-bs-toggle="tooltip"]:hover,
[data-bs-toggle="tooltip"]:focus-visible   // visible
[data-bs-placement="bottom" | "start" | "end"]
@supports (position-area: top)            // fixed + anchored, flip-block / flip-inline

The legacy .tooltip, .tooltip-inner and .tooltip-arrow classes still compile for static markup, but nothing in this theme generates them.