Skip to the page content

Buttons

Bootstrap's buttons, plus loading, hold to confirm and segmented.

Bootstrap reference

23 button types

Solid button

Bootstrap's filled variants, with fills and labels taken from the palette so every one reads clearly in light and dark.

Style
Show code
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary">Duplicate</button>
<button type="button" class="btn btn-success">Mark as paid</button>
<button type="button" class="btn btn-danger">Delete</button>
<button type="button" class="btn btn-warning">Hold stock</button>
<button type="button" class="btn btn-info">Details</button>
<button type="button" class="btn btn-dark">Publish</button>
<button type="button" class="btn btn-light">Draft</button>

Outline button

Bootstrap's outline variants for second-rank actions. They fill with their color on hover and when pressed.

Style
Show code
<button type="button" class="btn btn-outline-primary">Save changes</button>
<button type="button" class="btn btn-outline-secondary">Duplicate</button>
<button type="button" class="btn btn-outline-danger">Delete</button>

Soft button

A tinted fill with a deeper label, for actions that matter but shouldn't shout. Quieter than solid, clearer than outline, and it follows every palette.

Style
Show code
<button type="button" class="btn btn-soft-primary">Save draft</button>
<!-- btn-soft-secondary, -success, -danger, -warning, -info -->

A button that looks like a link, for the least important action in a row: a way back, a "see all" or a small fix-up.

Style
Show code
<button type="button" class="btn btn-link">View all orders</button>
<button type="button" class="btn btn-link btn-sm">Resend the code</button>

Pill button

Any variant with Bootstrap's rounded-pill utility. Good for follow buttons, tags you can act on and friendly calls to action.

Style
Show code
<button type="button" class="btn btn-primary rounded-pill">Begin free trial</button>
<button type="button" class="btn btn-outline-primary rounded-pill">Annual billing</button>

Gradient button

For the one action a screen is built around, like a hero call to action or an upgrade prompt. Two palette colors, mixed so the label reads at every point of the fill; with gradients off in Appearance it turns flat.

Style
Show code
<button type="button" class="btn btn-gradient">Upgrade to Pro</button>
<!-- btn-gradient-warm, btn-gradient-cool, btn-gradient-outline -->

Sizes

Large, default and small, from btn-lg and btn-sm. Keep one size per row so the labels line up.

Size
Show code
<button type="button" class="btn btn-primary btn-lg">Place order</button>
<button type="button" class="btn btn-primary">Place order</button>
<button type="button" class="btn btn-primary btn-sm">Place order</button>

Full-width button

Bootstrap's grid utilities stretch buttons across their container. Below, they stack on a phone and sit side by side from the small breakpoint.

Size
Show code
<div class="d-grid gap-2">
  <button type="button" class="btn btn-primary btn-lg">Pay $698.00</button>
</div>

<div class="d-grid gap-2 d-sm-flex justify-content-sm-end">
  <button type="button" class="btn btn-outline-secondary">Save for later</button>
  <button type="button" class="btn btn-primary">Continue to delivery</button>
</div>

Icon button

Icons with a label, and icons alone. An icon on its own needs an aria-label; a Bootstrap tooltip shows the same words to sighted users.

Content
Show code
<button type="button" class="btn btn-primary"><i class="bi bi-plus-lg me-1"></i>Add product</button>

<button type="button" class="btn btn-outline-secondary btn-square" aria-label="Edit"
        data-bs-toggle="tooltip" data-bs-title="Edit"><i class="bi bi-pencil"></i></button>

<!-- btn-icon: no border or fill until hovered -->
<button type="button" class="btn btn-icon" aria-label="Other actions"><i class="bi bi-three-dots"></i></button>

Counter button

A number that belongs to the button: a count set off in its own segment, or a badge on the corner of an icon button. Put the number in the accessible name too, so it is read out.

Content
Show code
<button type="button" class="btn btn-outline-secondary btn-count">
  <i class="bi bi-eye"></i>Watch<span class="btn-count-num">24</span>
</button>

<button type="button" class="btn btn-outline-secondary btn-square btn-badge" aria-label="Notifications, 3 unread">
  <i class="bi bi-bell"></i><span class="btn-badge-num" aria-hidden="true">3</span>
</button>
<!-- btn-badge-dot for a plain dot -->

Shortcut button

A button that shows its keyboard shortcut and answers to it. The key works anywhere on the page except while you are typing in a field. Press N, E or P to try it.

Content

No shortcut pressed yet.

Show code
<button type="button" class="btn btn-primary btn-kbd" data-basalt-shortcut="n" aria-keyshortcuts="N">
  <i class="bi bi-plus-lg"></i>New order<kbd class="btn-kbd-key">N</kbd>
</button>

Disabled button

The disabled attribute on a button, or .disabled with aria-disabled on a link. When the reason isn't obvious, wrap the button and put the reason in a tooltip on the wrapper.

State
Get the invoice
Show code
<button type="button" class="btn btn-primary" disabled>Place order</button>
<a class="btn btn-soft-primary disabled" role="button" aria-disabled="true">Get the invoice</a>

<!-- Disabled buttons get no pointer events, so the tooltip goes on a wrapper -->
<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 now</button>
</span>

Toggle button

Bootstrap's own data-bs-toggle="button" keeps aria-pressed in step; btn-toggle adds a second label and icon for the pressed state, and a little pop when it changes.

State
Show code
<button type="button" class="btn btn-outline-primary btn-toggle"
        data-bs-toggle="button" aria-pressed="false" aria-label="Follow Oakhaven Studio">
  <span class="btn-toggle-off"><i class="bi bi-plus-lg"></i>Follow</span>
  <span class="btn-toggle-on"><i class="bi bi-check2"></i>Following</span>
</button>

<!-- Icon only: the aria-label stays the same, aria-pressed says the state -->
<button type="button" class="btn btn-outline-secondary btn-toggle btn-square"
        data-bs-toggle="button" aria-pressed="false" aria-label="Favorite">
  <span class="btn-toggle-off"><i class="bi bi-star"></i></span>
  <span class="btn-toggle-on"><i class="bi bi-star-fill"></i></span>
</button>

Copy button

Copies a value and says so in place: the icon turns into a check and the label reads Copied for a moment. Point it at a field with a selector, or give it the text itself.

State
Order #41270
Show code
<!-- From a field -->
<button type="button" class="btn btn-outline-secondary btn-copy" data-basalt-copy="#coupon">
  <span class="btn-copy-idle"><i class="bi bi-clipboard"></i>Copy</span>
  <span class="btn-copy-done"><i class="bi bi-check2"></i>Copied</span>
</button>

<!-- From text; icon only needs an aria-label -->
<button type="button" class="btn btn-sm btn-outline-secondary btn-copy btn-copy-icon"
        data-basalt-copy="#41270" aria-label="Copy order number">…</button>

Loading button

One button that moves through idle, loading, success and error without changing width. It says it is busy to screen readers, ignores double clicks while it works and can show real progress. Try all three.

State

The stock sync fails the first time, so you can see the error state.

  • Idle
  • Loading
  • Progress
  • Success
  • Error
Show code
<!-- One span per state; they share a grid cell, so the width never jumps. -->
<button type="button" class="btn btn-primary btn-loading" id="save">
  <span class="btn-loading-state btn-loading-idle"><i class="bi bi-cloud-arrow-up"></i>Save changes</span>
  <span class="btn-loading-state btn-loading-busy"><span class="spinner-border spinner-border-sm"></span>Saving</span>
  <span class="btn-loading-state btn-loading-done"><i class="bi bi-check2"></i>Saved</span>
  <span class="btn-loading-state btn-loading-fail"><i class="bi bi-arrow-clockwise"></i>Try again</span>
</button>

<!-- Add btn-loading-progress and a data-btn-progress slot for a fill -->
<span class="btn-loading-state btn-loading-busy">Exporting <span data-btn-progress>0%</span></span>

<script>
  basaltButtonState(save, 'loading');   // idle | loading | success | error
  basaltButtonProgress(save, 0.4);      // 0 to 1, for btn-loading-progress
  fetch('/api/save').then(() => basaltButtonState(save, 'success'))
                    .catch(() => basaltButtonState(save, 'error'));
</script>

Button group

Related buttons joined into one piece with btn-group, across or stacked with btn-group-vertical.

Group
Show code
<div class="btn-group" role="group" aria-label="Order tools">
  <button type="button" class="btn btn-outline-secondary">Print</button>
  <button type="button" class="btn btn-outline-secondary">Email</button>
  <button type="button" class="btn btn-outline-secondary">Duplicate</button>
</div>

<div class="btn-group-vertical" role="group" aria-label="Move line">…</div>

Toolbar

Several groups in one row with btn-toolbar and role="toolbar". It wraps onto a second line when space runs out.

Group
Show code
<div class="btn-toolbar gap-2" role="toolbar" aria-label="Editing tools">
  <div class="btn-group" role="group" aria-label="Emphasis">
    <button type="button" class="btn btn-outline-secondary btn-square" aria-label="Bold"><i class="bi bi-type-bold"></i></button>
    …
  </div>
  <div class="btn-group" role="group" aria-label="History">…</div>
</div>

Checkbox and radio buttons

Bootstrap's btn-check: real radios and checkboxes drawn as buttons. Pick one billing period; check as many add-ons as you like. No script needed.

Group
Show code
<input type="radio" class="btn-check" name="billing" id="billing-1" checked>
<label class="btn btn-outline-primary" for="billing-1">Monthly</label>

<input type="checkbox" class="btn-check" id="portal">
<label class="btn btn-outline-secondary" for="portal">Customer portal</label>

Split button

A main action with a menu of close relatives behind the arrow, from dropdown-toggle-split. The arrow needs hidden text so it has a name.

Group
Show code
<div class="btn-group">
  <button type="button" class="btn btn-primary">Save draft</button>
  <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split"
          data-bs-toggle="dropdown" aria-expanded="false">
    <span class="visually-hidden">More ways to save</span>
  </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Publish now</a></li>
    …
  </ul>
</div>

Segmented control

A set of radio buttons drawn as one control, with a thumb that slides to the choice. The arrow keys move between options because they are real radios, and it works without the script, just without the slide.

Group

412 orders this week

Show code
<div class="basalt-segmented" role="radiogroup" aria-label="Sales period" data-basalt-segmented>
  <input type="radio" class="btn-check" name="period" id="period-day">
  <label class="basalt-segmented-option" for="period-day">Day</label>
  <input type="radio" class="btn-check" name="period" id="period-week" checked>
  <label class="basalt-segmented-option" for="period-week">Week</label>
  <input type="radio" class="btn-check" name="period" id="period-month">
  <label class="basalt-segmented-option" for="period-month">Month</label>
</div>

<!-- basalt-segmented-sm for toolbars, basalt-segmented-block to fill the row -->

Speed dial

One round button that opens a short stack of labeled actions. It closes on Escape, on a click outside or after a choice; the arrow keys move through the actions. Add basalt-speed-dial-fixed to pin it to the corner of the screen.

Group

Orders

Open the plus button to pick an action.

Show code
<div class="basalt-speed-dial" data-basalt-speed-dial>
  <div class="basalt-speed-dial-actions" id="dial-actions" role="group" aria-label="Quick actions">
    <button type="button" class="basalt-speed-dial-action">
      <span class="basalt-speed-dial-label">New order</span>
      <span class="basalt-speed-dial-icon"><i class="bi bi-bag-plus"></i></span>
    </button>
    …
  </div>
  <button type="button" class="btn btn-primary basalt-speed-dial-toggle"
          aria-expanded="false" aria-controls="dial-actions" aria-label="Quick actions">
    <i class="bi bi-plus-lg"></i>
  </button>
</div>

Two-step confirm

The first click turns the button into its own question; a second click within three seconds does it. Waiting, pressing Escape or moving focus away puts it back, and the bar along the bottom shows the time left.

Confirm
  • Two-Tone OxfordsML-OXFD, 1 unit, $850.00
  • Shield SunglassesML-SHLD, 2 pairs, $1,040.00

Two items in the basket.

Show code
<button type="button" class="btn btn-outline-danger btn-confirm" data-basalt-confirm data-confirm-ms="3000">
  <span class="btn-confirm-idle"><i class="bi bi-x-lg"></i>Remove</span>
  <span class="btn-confirm-ask">Click again to remove</span>
</button>

<script>
  // Fired on the second click only.
  button.addEventListener('basalt:confirm', () => removeLine('fl-mnt'));
</script>

Hold to confirm

For actions that are hard to undo. The button fills while it is held with the mouse, a finger, Enter or Space, and only acts once it is full. A quick click does nothing, and the label tells you to keep going.

Confirm
Order #4127Bar Loafers, 2 units, $1,580.00
Refund $198.00Returned chalk-stripe suit, to the card ending 4242

Nothing deleted yet.

Show code
<button type="button" class="btn btn-danger basalt-hold" data-basalt-hold data-hold-ms="1500">
  <span class="basalt-hold-state basalt-hold-idle"><i class="bi bi-trash"></i>Hold to delete</span>
  <span class="basalt-hold-state basalt-hold-busy">Keep holding</span>
  <span class="basalt-hold-state basalt-hold-done"><i class="bi bi-check2"></i>Deleted</span>
</button>

<script>
  // basalt.js fires this once the button has been held long enough.
  button.addEventListener('basalt:confirm', () => deleteOrder(4127));
</script>