Skip to the page content

Tooltips and popovers

Short labels on hover and focus, and richer popovers.

Bootstrap's tooltip docs

15 types

Tooltip placements

Top, right, bottom or left with data-bs-placement. If there isn't room, the tooltip flips to the other side on its own.

Tooltip
Show code
<button type="button" class="btn btn-outline-secondary"
        data-bs-toggle="tooltip" data-bs-placement="right"
        data-bs-title="Tooltip on the right">Right</button>

<script>
  document.querySelectorAll('[data-bs-toggle="tooltip"]')
    .forEach((el) => new bootstrap.Tooltip(el));
</script>

Tooltip tones

Bootstrap's customClass option with six tones that follow the palette. Ink is the default; save the others for tooltips that carry a state.

Tooltip
Show code
<button type="button" class="btn btn-outline-secondary"
        data-bs-toggle="tooltip"
        data-bs-custom-class="basalt-tip-warning"
        data-bs-title="Only 7 units left">Warning</button>

<!-- Tones: basalt-tip-light, --primary, --success, --warning, --danger -->

HTML tooltip

With data-bs-html="true" the title can hold markup, such as a bold name over a second line. Bootstrap's sanitizer strips anything unsafe.

Tooltip
Show code
<button type="button" aria-label="Sharon Oakley"
data-bs-toggle="tooltip" data-bs-html="true"
data-bs-title="&lt;strong&gt;Sharon Oakley&lt;/strong&gt;&lt;br&gt;Care manager">SO</button>

Delayed tooltip

A short delay stops tooltips flashing up as the pointer crosses a busy area. Set show and hide separately with data-bs-delay.

Tooltip
Show code
<button type="button" class="btn btn-outline-secondary"
data-bs-toggle="tooltip"
data-bs-delay='{"show":500,"hide":150}'
data-bs-title="Waited half a second">500 ms delay</button>

Tooltip on a disabled button

A disabled button can't be hovered or focused, so the tooltip goes on a wrapper that can. Use it to say why something is off.

Tooltip
Show code
<span class="d-inline-block" tabindex="0"
      data-bs-toggle="tooltip" data-bs-title="Add a delivery address first">
  <button type="button" class="btn btn-primary" disabled>Ship order</button>
</span>

Tooltip with shortcut

Icon buttons name themselves and show their key combination. The first tooltip waits half a second; once one is open, the next opens straight away as you move along. Arrow keys move through the toolbar.

Tooltip

Visit note: cleaned the oven and shampooed the hall carpet. Next deep clean is due in March.

Show code
<!-- "mod" shows as ⌘ on a Mac and Ctrl elsewhere -->
<div role="toolbar" aria-label="Formatting" data-basalt-toolbar data-basalt-tip-group>
  <button type="button" aria-label="Bold" data-basalt-kbd="mod+B">
    <i class="bi bi-type-bold" aria-hidden="true"></i>
  </button>
  <button type="button" aria-label="Italic" data-basalt-kbd="mod+I" tabindex="-1">
    <i class="bi bi-type-italic" aria-hidden="true"></i>
  </button>
</div>

Overflow tooltip

Only text that is actually cut off gets a tooltip and a tab stop. Drag the slider: as the column widens, names that fit lose their tooltip.

Tooltip
190 px
Products with stock
Product Category Stock
Sculpted Shoulder Blazer Clothing 42
Tiered Organza Dress, with monthly plan Clothing 18
Cat-Eye Sunglasses Accessories 96
Shield Sunglasses, one size Accessories 23
Chalk-Stripe Suit, boxy fit, with ribbed hem Clothing 7

3 of 5 names are cut off.

Show code
<!-- The tooltip and tab stop appear only while the text is cut off -->
<td>
  <span class="basalt-ellipsis" data-basalt-truncate-tip>
    Tiered Organza Dress, with monthly plan
  </span>
</td>

Feedback tooltip

The tooltip says what a button will do, then confirms that it did. The change is also read out, and the label goes back after a moment.

Tooltip
  • Order number#4821-KX
  • Tracking code1Z 999 AA1 01 2345 6784
  • Discount codeSCULPT20-15
Show code
<button type="button" aria-label="Copy order number"
        data-bs-title="Copy order number"
        data-basalt-copy="#4821-KX"
        data-basalt-copy-done="Order number copied">
  <i class="bi bi-copy" aria-hidden="true"></i>
</button>

Popover

Bootstrap's popover with a title and a body, in each of the four placements. Click to open and click again to close.

Popover
Show code
<button type="button" class="btn btn-outline-secondary"
        data-bs-toggle="popover" data-bs-placement="top"
        data-bs-title="Service window"
        data-bs-content="Arrival windows are two hours.">Top</button>

<script>
  document.querySelectorAll('[data-bs-toggle="popover"]')
    .forEach((el) => new bootstrap.Popover(el));
</script>

Popover triggers

What opens and closes the popover, set with data-bs-trigger. Focus closes it on the next click anywhere, which suits a quick explanation.

Popover
Dismiss on next click
Show code
<!-- Focus needs an element that can take focus, like an a with tabindex -->
<a tabindex="0" class="btn btn-outline-secondary" role="button"
   data-bs-toggle="popover" data-bs-trigger="focus"
   data-bs-title="Focus"
   data-bs-content="Closes on your next click.">Dismiss on next click</a>

Confirm popover

Asks before a small destructive action, right where you clicked, instead of a full dialog. Focus starts on Cancel, Escape backs out, and a removed line can be undone.

Popover
  • Leather Trench CoatML-TRCH, 2 units $6,400.00
  • Shield SunglassesML-SHLD, 3 pairs $1,560.00
  • E-Gift Card, $250ML-GIFT250, 2 cards $500.00

Order total $8,460.00

Show code
<button type="button" aria-label="Remove Leather Trench Coat"
        data-basalt-popconfirm
        data-basalt-popconfirm-title="Remove Leather Trench Coat?"
        data-basalt-popconfirm-text="It comes off this order."
        data-basalt-popconfirm-ok="Remove">
  <i class="bi bi-trash3" aria-hidden="true"></i>
</button>

<script>
  // Fires only when the person presses the confirm button.
  button.addEventListener('basalt:confirm', () => removeLine(button));
</script>

Edit-in-place popover

A one-field form that opens beside a value. Enter saves, Escape cancels, and the number is checked before it is kept.

Popover
Stock and price by product
Product In stock Price
Sculpted Shoulder Blazer 42 units $1,290.00
Leather Trench Coat 18 units $3,200.00
Shield Sunglasses 7 units $520.00

Press a pencil to change a value.

Show code
<span id="stock-blazer">42 units</span>
<button type="button" aria-label="Edit stock for Sculpted Shoulder Blazer"
        data-basalt-edit
        data-basalt-edit-label="Units in stock"
        data-basalt-edit-value="42"
        data-basalt-edit-min="0" data-basalt-edit-max="999"
        data-basalt-edit-step="1"
        data-basalt-edit-suffix="units">
  <i class="bi bi-pencil" aria-hidden="true"></i>
</button>

<script>
  button.addEventListener('basalt:edit', (e) => {
    document.getElementById('stock-blazer').textContent = e.detail.value + ' units';
  });
</script>

Toggletip

A note behind an info button that opens on click, not hover, so it works on touch screens and is read out when it opens. Escape or a click elsewhere closes it.

Toggletip

Customers get a reminder the day before each visit

Show code
<label class="form-label" for="job-type">Visit type</label>
<span class="basalt-toggletip"
      data-basalt-toggletip="Sets how long the visit is booked for.">
  <button type="button" class="basalt-toggletip-btn"
          aria-label="About visit type" aria-expanded="false">
    <i class="bi bi-info-circle" aria-hidden="true"></i>
  </button>
  <!-- Filled on open, so screen readers read it -->
  <span class="basalt-toggletip-bubble" role="status" hidden></span>
</span>

Hover card

A preview of a person or record that opens when you rest on a name, or tab to it. It stays open while the pointer is over it, so its buttons can be used.

Hover card
  • Sharon Oakley booked 6 seats on live training for the new team. Today, 8:14 am
  • Earl Mann asked to move Friday's training session to Thursday. Yesterday, 4:40 pm
  • Ann Rudd left five stars on the Travel Planner add-on. Monday, 11:02 am
Show code
<a href="company-details.html" data-basalt-hovercard="#card-sharon">Sharon Oakley</a>

<template id="card-sharon">
  <div>
    <div class="basalt-hovercard-head">
      <span class="basalt-hovercard-avatar" aria-hidden="true">SO</span>
      <div>
        <p class="basalt-hovercard-name">Sharon Oakley</p>
        <p class="basalt-hovercard-role">Care manager, Oakhaven Studio</p>
      </div>
    </div>
    <dl class="basalt-hovercard-stats">
      <div><dt>Orders</dt><dd>12</dd></div>
      <div><dt>Spent</dt><dd>$18.4k</dd></div>
      <div><dt>Since</dt><dd>2023</dd></div>
    </dl>
    <div class="basalt-hovercard-actions">
      <a class="btn btn-sm btn-primary" href="company-details.html">View account</a>
    </div>
  </div>
</template>

Tour popover

A popover that walks through a screen one step at a time. The part being described gets a ring, and the popover carries the step count, Back and Next. Arrow keys move between steps and Escape ends the tour.

Tour

Four steps through the orders screen.

Recent orders
Order Customer Items Status Total
#4821 Arbor North Studio 6 Sculpted Shoulder Blazers To pack $7,740.00
#4820 The Silk Room 4 Leather Trench Coats, 4 Bar Loafers Shipped $15,960.00
#4817 Hartley & Briar 10 Two-Tone Oxfords Delivered $8,500.00
Show code
<!-- Any element can be a step. Steps run in number order. -->
<div class="basalt-tour-scope" data-basalt-tour>
  <button type="button" class="btn btn-primary btn-sm"
          data-basalt-tour-start>Start the tour</button>
  <p aria-live="polite" data-basalt-tour-status></p>

  <input type="search" class="form-control" aria-label="Search orders"
         data-basalt-tour-step="1"
         data-basalt-tour-title="Search every order"
         data-basalt-tour-text="Type an order number, a customer or a product."
         data-basalt-tour-placement="bottom">

  <button type="button" class="btn btn-outline-secondary"
          data-basalt-tour-step="2"
          data-basalt-tour-title="Send it to the courier"
          data-basalt-tour-text="Export today's list as a CSV file."
          data-basalt-tour-placement="left">Export</button>
</div>