Skip to the page content

Modals

Dialogs that wait for an answer, from confirms to a lightbox.

Bootstrap docs

17 dialog types

Basic dialog

Bootstrap's modal as it comes: header with a close button, body and footer. Styled with the palette, a softer backdrop and a short scale-in instead of the slide from the top.

Layout
Show code
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#publish">
  Open the dialog
</button>

<div class="modal fade" id="publish" tabindex="-1" role="dialog" aria-labelledby="publish-title" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="publish-title">Send the October release notes?</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <p>The notes on the new schedule board go to all 2,140 accounts at 7 am tomorrow.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Not yet</button>
        <button type="button" class="btn btn-primary">Send</button>
      </div>
    </div>
  </div>
</div>

Dialog sizes

Bootstrap's four widths, drawn to scale. Click a bar to open a dialog at that size. Below 576px every size fills the screen width less a small margin.

Layout
Show code
<div class="modal-dialog modal-sm">…</div>   <!-- 300px -->
<div class="modal-dialog">…</div>            <!-- 500px -->
<div class="modal-dialog modal-lg">…</div>   <!-- 800px -->
<div class="modal-dialog modal-xl">…</div>   <!-- 1140px -->

Vertically centered

Add .modal-dialog-centered to sit the dialog in the middle of the window rather than near the top. Combine it with the scrollable class for long content.

Layout
Show code
<div class="modal-dialog modal-dialog-centered">…</div>
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable">…</div>

Scrollable body

With .modal-dialog-scrollable the header and footer stay in view and only the body scrolls. Without it the whole dialog scrolls with the page.

Layout
Show code
<!-- Only the body scrolls -->
<div class="modal-dialog modal-dialog-scrollable">…</div>

<!-- The dialog scrolls with the page -->
<div class="modal-dialog">…</div>

Responsive full screen

Bootstrap can make a dialog fill the screen only below a breakpoint, so a phone gets the whole screen while a desktop keeps a normal box. Pick a class and resize the window to watch it switch.

Layout
Show code
<div class="modal-dialog modal-fullscreen">…</div>
<div class="modal-dialog modal-fullscreen-sm-down">…</div>
<div class="modal-dialog modal-fullscreen-md-down">…</div>
<div class="modal-dialog modal-fullscreen-lg-down">…</div>
<div class="modal-dialog modal-fullscreen-xl-down">…</div>
<div class="modal-dialog modal-fullscreen-xxl-down">…</div>

Static backdrop

With data-bs-backdrop="static" a click outside only nudges the dialog, and data-bs-keyboard="false" turns off Esc. Use it when leaving halfway would lose work.

Behavior

Open it, then click the dimmed page. The dialog stays and gives a small bounce.

Show code
<div class="modal fade" id="stock" data-bs-backdrop="static" data-bs-keyboard="false"
     tabindex="-1" role="dialog" aria-labelledby="stock-title" aria-hidden="true">
  …
</div>

Toggle between dialogs

A button in one dialog can open another in its place, with data-bs-toggle="modal" pointing at the second. Only one is open at a time, and the second can lead back.

Behavior
  1. 1Choose a delivery address
  2. 2Add a new one
  3. 3Back to the list
Show code
<!-- Inside the first dialog -->
<button type="button" class="btn btn-outline-secondary"
        data-bs-target="#address-new" data-bs-toggle="modal">Add a new address</button>

<!-- Inside the second dialog -->
<button type="button" class="btn btn-outline-secondary"
        data-bs-target="#address-list" data-bs-toggle="modal">Back to the list</button>

Varying content

One dialog, filled by whichever button opened it. Each button carries a data-bs-whatever value, and the show.bs.modal event reads it from relatedTarget.

Behavior
Show code
<button type="button" class="btn btn-primary" data-bs-toggle="modal"
        data-bs-target="#message" data-bs-whatever="Ann Dillon">Message Ann</button>

<script>
  message.addEventListener('show.bs.modal', (e) => {
    const name = e.relatedTarget.getAttribute('data-bs-whatever');
    message.querySelector('.modal-title').textContent = 'Message ' + name;
  });
</script>

Typed confirmation

The strongest check: the button stays off until the exact name is typed. A bar fills as the letters match and says where it stops matching, so a typo is easy to spot.

Confirm
Show code
<div class="basalt-type-confirm" data-basalt-type-confirm="Avocet Robotics">
  <label class="form-label" for="close-name">Customer name</label>
  <input type="text" class="form-control" id="close-name" autocomplete="off"
         aria-describedby="close-state">
  <div class="basalt-type-confirm-meter" aria-hidden="true"><span></span></div>
  <p class="basalt-type-confirm-state" id="close-state" aria-live="polite"></p>
</div>
<button type="button" class="btn btn-danger" data-basalt-type-confirm-action disabled>
  Close account
</button>

Hold-to-confirm dialog

For actions that can't be undone. The dialog lists exactly what will happen, and the button has to be held down for a moment, with the mouse, a finger or Enter, so a stray click does nothing.

Confirm
Show code
<div class="modal fade basalt-modal-confirm" id="del" tabindex="-1" role="dialog" aria-labelledby="del-title" aria-describedby="del-text" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <div class="basalt-confirm">
        <span class="basalt-confirm-icon" aria-hidden="true"><i class="bi bi-trash3"></i></span>
        <h2 class="basalt-confirm-title" id="del-title">Delete 3 products?</h2>
        <p class="basalt-confirm-text" id="del-text">They come off the store straight away.</p>
        <ul class="basalt-confirm-list">
          <li><i class="bi bi-x-circle" aria-hidden="true"></i>Leather Apron, black</li>
        </ul>
        <div class="basalt-confirm-actions">
          <button type="button" class="btn btn-danger basalt-hold" data-basalt-hold data-hold-ms="1200">
            Hold to delete
          </button>
          <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Keep them</button>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- Add basalt-confirm-warning or --primary for a milder tone. -->

Form dialog

Validates on submit, shows a spinner while saving and ends on a clear success state. If you have typed something and try to close it, the dialog asks before throwing the changes away instead of closing on you.

Form
Show code
<div class="modal fade" id="discount" tabindex="-1" role="dialog" aria-labelledby="discount-title"
     aria-hidden="true" data-basalt-modal-guard>
  <div class="modal-dialog modal-dialog-centered">
    <form class="modal-content" novalidate data-basalt-modal-form>
      <div class="modal-header">…</div>
      <div class="modal-body">…fields…</div>
      <!-- Shown instead of closing while the form has unsaved changes -->
      <div class="basalt-modal-guard" role="alert" hidden>
        <i class="bi bi-exclamation-triangle" aria-hidden="true"></i>
        <p class="basalt-modal-guard-text">Discard your changes?</p>
        <button type="button" class="btn btn-sm btn-outline-secondary" data-basalt-guard-keep>Keep editing</button>
        <button type="button" class="btn btn-sm btn-danger" data-basalt-guard-discard>Discard</button>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel</button>
        <button type="submit" class="btn btn-primary" data-busy-label="Saving…">Create code</button>
      </div>
      <div class="basalt-done" hidden>…success message…</div>
    </form>
  </div>
</div>

Multi-step dialog

A long form split into short steps. The header shows where you are, Next checks only the fields on the current step, and the last step reads your answers back before anything is saved.

Form
Show code
<div class="modal-content" data-basalt-dialog-steps>
  <div class="basalt-dialog-body">
    <ol class="basalt-dialog-steps">
      <li class="basalt-dialog-steps-item">
        <span class="basalt-dialog-steps-dot"><span class="basalt-dialog-steps-num">1</span><i class="bi bi-check-lg"></i></span>
        <span class="basalt-dialog-steps-label">Plan</span>
      </li>
      <!-- one <li> per step -->
    </ol>
    <fieldset data-basalt-step-panel>…fields for step 1…</fieldset>
    <fieldset data-basalt-step-panel hidden>…step 2…</fieldset>
    <fieldset data-basalt-step-panel hidden>
      <dd data-basalt-step-summary="plan"></dd> <!-- filled from the field named "plan" -->
    </fieldset>
  </div>
  <div class="basalt-dialog-foot">
    <button type="button" class="btn btn-outline-secondary" data-basalt-step-back>Back</button>
    <button type="button" class="btn btn-primary" data-basalt-step-next>Next</button>
    <button type="submit" class="btn btn-primary" data-basalt-step-finish hidden>Start plan</button>
  </div>
</div>

Dialog with live preview

The form on one side and the result on the other, redrawn as you type. The two columns follow the dialog's own width, so it stacks by itself on narrow screens.

Form
Show code
<div class="modal-dialog modal-dialog-centered modal-lg">
  <div class="modal-content basalt-dialog-split">
    <div class="basalt-dialog-head">…</div>
    <div class="basalt-dialog-body basalt-dialog-split-body">
      <div><!-- the form --></div>
      <aside class="basalt-preview-panel">
        <span class="basalt-preview-panel-label">Preview</span>
        <!-- the thing being edited, updated on input -->
      </aside>
    </div>
    <div class="basalt-dialog-foot">…</div>
  </div>
</div>

Side sheet

A dialog pinned to the right edge at full height, for a record that needs more room than a centered box. Unlike an offcanvas it keeps focus inside and the page waits behind it. Header and footer stay put while the middle scrolls.

Sheet
Show code
<div class="modal fade basalt-modal-sheet" id="order" tabindex="-1" role="dialog" aria-labelledby="order-title" aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="order-title">Order #9142</h2>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">…</div>
      <div class="modal-footer">…</div>
    </div>
  </div>
</div>

<!-- Width: set --basalt-sheet-width in your stylesheet. From the left: add basalt-modal-sheet-start. -->

Full-screen dialog

Takes the whole window for work that needs space, with an app bar in place of the usual header: title, a saved indicator and the main actions. From 992px up the settings sit beside the editor; below that they stack.

Sheet
Show code
<div class="modal fade basalt-modal-full" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit-title" aria-hidden="true">
  <div class="modal-dialog modal-fullscreen">
    <div class="modal-content">
      <div class="basalt-appbar">
        <button type="button" class="btn btn-icon" data-bs-dismiss="modal" aria-label="Close"><i class="bi bi-x-lg"></i></button>
        <h2 class="basalt-appbar-title" id="edit-title">Edit Sculpted Shoulder Blazer</h2>
        <span class="basalt-appbar-status" aria-live="polite"><i class="bi bi-cloud-check"></i>Saved</span>
        <div class="basalt-appbar-actions">
          <button type="button" class="btn btn-primary">Publish</button>
        </div>
      </div>
      <div class="modal-body">
        <div class="basalt-modal-grid">
          <div><!-- main --></div>
          <aside><!-- settings --></aside>
        </div>
      </div>
    </div>
  </div>
</div>

Lightbox

Click a picture to open it large. Arrow keys and the side buttons step through the set, the strip at the bottom jumps anywhere, and focus goes back to the picture you started from on close.

Media
Show code
<ul data-basalt-lightbox-set="#gallery">
  <li>
    <button type="button" data-basalt-lightbox-item data-caption="Sculpted Shoulder Blazer"
            data-note="$1,290. Built by hand in Illinois." aria-label="View Sculpted Shoulder Blazer">
      <img src="blazer-front.jpg" alt="">
    </button>
  </li>
</ul>

<div class="modal fade basalt-lightbox" id="gallery" tabindex="-1" role="dialog" aria-label="Collection photos" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-xl">
    <div class="modal-content">
      <div class="basalt-lightbox-stage" data-basalt-lightbox-stage>
        <button type="button" class="basalt-lightbox-nav basalt-lightbox-nav-prev" data-basalt-lightbox-prev aria-label="Previous picture"><i class="bi bi-chevron-left"></i></button>
        <button type="button" class="basalt-lightbox-nav basalt-lightbox-nav-next" data-basalt-lightbox-next aria-label="Next picture"><i class="bi bi-chevron-right"></i></button>
      </div>
      <div class="basalt-lightbox-bar">
        <div class="basalt-lightbox-caption"><strong data-basalt-lightbox-caption></strong><span data-basalt-lightbox-note></span></div>
        <span class="basalt-lightbox-count" data-basalt-lightbox-count></span>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="basalt-lightbox-thumbs" data-basalt-lightbox-thumbs></div>
    </div>
  </div>
</div>

Command palette

A search box over grouped commands. Type to narrow the list, move with the arrow keys and press Enter to run one. Matches are underlined and empty groups fold away. The same component works on the page or inside a dialog.

Command

Try typing or .

↑ ↓
Move through results
Home End
First or last result
Enter
Run the highlighted one
Esc
Clear, then close

Nothing run yet.

Go to
OrdersSales
ProductsCatalog
CustomersAccounts
SubscriptionsBilling
InventoryStock
Create
New orderN then O
New productN then P
New discount codeN then D
Invite a teammateTeam
Recent
Order #9142 · Arbor North Studio2 min ago
Sculpted Shoulder BlazerProduct
Christopher VanceCustomer
Express Delivery PassAdd-on
Show code
<div class="modal fade basalt-modal-command" id="palette" tabindex="-1" role="dialog" aria-label="Command palette" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="basalt-command" data-basalt-command>
        <div class="basalt-command-search">
          <i class="bi bi-search" aria-hidden="true"></i>
          <input type="text" class="basalt-command-input" role="combobox"
                 aria-expanded="true" aria-controls="palette-list"
                 aria-autocomplete="list" aria-label="Search commands">
        </div>
        <div class="basalt-command-list" id="palette-list" role="listbox" aria-label="Results">
          <div class="basalt-command-group" role="group" aria-labelledby="palette-g1">
            <div class="basalt-command-heading" id="palette-g1">Go to</div>
            <div class="basalt-command-item" role="option" id="palette-orders"
                 aria-selected="false" data-value="orders" data-keywords="sales list">
              <span class="basalt-command-icon" aria-hidden="true"><i class="bi bi-bag-check"></i></span>
              <span class="basalt-command-label">Orders</span>
              <span class="basalt-command-hint">Sales</span>
            </div>
          </div>
        </div>
        <div class="basalt-command-empty" hidden>
          <p>Nothing matches "<span data-basalt-command-term></span>".</p>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  // Fires when a result is chosen, by click or Enter.
  palette.addEventListener('basalt:command', (e) => {
    applyChoice(e.detail.value, e.detail.label);
  });
</script>