Skip to the page content

Dropdowns

Menus that drop down, from plain to searchable and multi-select.

Bootstrap docs

19 dropdown types

Plain dropdown

A button with data-bs-toggle="dropdown" and a list of items. Bootstrap handles opening, closing, the arrow keys and Escape.

Trigger
Show code
<div class="dropdown">
  <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Actions</button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Edit details</a></li>
    <li><a class="dropdown-item" href="#">Make a copy</a></li>
  </ul>
</div>

Split button

The main action on the left and its relatives behind the arrow, from dropdown-toggle-split. The arrow needs hidden text so it has a name.

Trigger
Show code
<div class="btn-group">
  <button type="button" class="btn btn-primary">Save</button>
  <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown">
    <span class="visually-hidden">More ways to save</span>
  </button>
  <ul class="dropdown-menu">…</ul>
</div>

Icon trigger

A dropdown behind an icon, as at the end of a table row. Drop the caret with no dropdown-toggle class, give the button an aria-label and align the menu to the end.

Trigger
#3086 Annabelle Franklin $1,298.00
#3085 Cheryl Sorensen $236.00
Show code
<div class="dropdown">
  <button type="button" class="btn btn-icon" data-bs-toggle="dropdown" aria-expanded="false"
          aria-label="More actions for order #3086"><i class="bi bi-three-dots-vertical"></i></button>
  <ul class="dropdown-menu dropdown-menu-end">…</ul>
</div>

Auto-close

data-bs-auto-close decides which clicks close the menu: any click, clicks inside only, clicks outside only, or none, so it closes only from its button or Escape.

Trigger
Show code
<button data-bs-toggle="dropdown" data-bs-auto-close="true">Any click</button>
<button data-bs-toggle="dropdown" data-bs-auto-close="inside">Inside only</button>
<button data-bs-toggle="dropdown" data-bs-auto-close="outside">Outside only</button>
<button data-bs-toggle="dropdown" data-bs-auto-close="false">Button only</button>

Context menu

A menu that opens where you right-click, for actions on a row. From the keyboard, focus a row and press Shift+F10 or the menu key. It uses Bootstrap's menu styles without a toggle button.

Trigger
  • #3086Annabelle FranklinPacking$1,298.00
  • #3085Cheryl SorensenPaid$236.00
  • #3084Eleanor FairweatherShipped$2,145.00

Right-click a row, or focus it and press Shift+F10.

Show code
<ul data-basalt-context="#order-menu">
  <li tabindex="0">#3086 Annabelle Franklin $1,298.00</li>
</ul>

<ul class="dropdown-menu basalt-context-menu" id="order-menu" role="menu" aria-label="Actions for this order">
  <li role="none"><button type="button" class="dropdown-item" role="menuitem">Open</button></li>
  …
</ul>

<script>
  // detail.target is the row that was right-clicked.
  menu.addEventListener('basalt:context', (e) => { current = e.detail.target; });
</script>

Headers and dividers

dropdown-header names a group, dropdown-divider separates groups and dropdown-item-text holds text that isn't a link.

Items
Show code
<ul class="dropdown-menu">
  <li><span class="dropdown-item-text">Signed in as ada@example.com</span></li>
  <li><hr class="dropdown-divider"></li>
  <li><h3 class="dropdown-header">Company</h3></li>
  <li><a class="dropdown-item" href="#">Team</a></li>
</ul>

Active and disabled items

.active with aria-current marks the current choice; .disabled with aria-disabled shows one that can't be picked yet.

Items
Show code
<li><a class="dropdown-item active" href="#" aria-current="true">US dollar (USD)</a></li>
<li><a class="dropdown-item disabled" aria-disabled="true">Japanese yen (JPY)</a></li>

Rich items

Items with an icon tile, a line of explanation and a key. While the menu is open, pressing a letter jumps to the item that starts with it, on every menu on this page.

Items

Open the menu and press O.

Show code
<ul class="dropdown-menu basalt-dd-rich">
  <li><button type="button" class="dropdown-item basalt-dd-item">
    <span class="basalt-dd-item-icon basalt-dd-item-icon-1"><i class="bi bi-box-seam"></i></span>
    <span class="basalt-dd-item-text">
      <span class="basalt-dd-item-title">Product</span>
      <span class="basalt-dd-item-sub">Add a piece, accessory or extra</span>
    </span>
    <kbd class="basalt-dd-item-kbd">P</kbd>
  </button></li>
</ul>
<!-- --1 to --4 take the first four chart colors -->

Nested submenu

An item that opens a second menu to the side, which Bootstrap 5 dropped. Hover or click it, or press the right arrow; the left arrow and Escape close it again and put you back where you were.

Items

Order #3086 is in Packing, going by FedEx.

Show code
<div class="dropdown">
  <button class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown"
          data-bs-auto-close="outside">Order #3086</button>
  <ul class="dropdown-menu">
    <li class="dropdown-submenu">
      <button type="button" class="dropdown-item dropdown-submenu-toggle"
              aria-haspopup="true" aria-expanded="false">Move to</button>
      <ul class="dropdown-menu">
        <li><button type="button" class="dropdown-item">Packing</button></li>
        …
      </ul>
    </li>
  </ul>
</div>

Confirm item

A destructive item that asks inside the menu instead of opening a dialog. The first choice turns it into the question and keeps the menu open; the second does it. Leaving the item or closing the menu cancels.

Items
Bar Loafers ML-LOAF, $790

Bar Loafers is in the store.

Show code
<li><button type="button" class="dropdown-item dropdown-item-confirm" data-basalt-confirm-item>
  <span class="dropdown-item-confirm-idle"><i class="bi bi-trash"></i>Delete product</span>
  <span class="dropdown-item-confirm-ask"><i class="bi bi-exclamation-triangle"></i>Click again to delete</span>
</button></li>

<script>
  item.addEventListener('basalt:confirm', () => deleteProduct('ML-LOAF'));
</script>

Direction

Open up with dropup, sideways with dropend and dropstart, or centered under the button with dropdown-center. Bootstrap flips a menu that would leave the screen.

Placement
Show code
<div class="dropup">…</div>
<div class="dropend">…</div>
<div class="dropstart">…</div>
<div class="dropdown-center">…</div>

Alignment

dropdown-menu-end lines the menu up with the right edge of its button, dropdown-menu-lg-end does that only from the large breakpoint, and data-bs-offset moves it away from the button.

Placement
Show code
<ul class="dropdown-menu dropdown-menu-end">…</ul>
<ul class="dropdown-menu dropdown-menu-lg-end">…</ul>
<button data-bs-toggle="dropdown" data-bs-offset="0,14">…</button>

Checkbox menu

Plain Bootstrap checkboxes in a menu, with data-bs-auto-close="outside" so it stays open while you choose. Good for choosing table columns.

Select
Show code
<div class="dropdown">
  <button class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown"
          data-bs-auto-close="outside">Columns</button>
  <div class="dropdown-menu px-3 py-2">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" id="col-1" checked>
      <label class="form-check-label" for="col-1">Product</label>
    </div>
  </div>
</div>

Multi-select

Checkboxes in a menu that stays open while you choose. A select-all box shows when only some are checked, the button counts the choices and each one shows as a chip you can remove.

Select
    Show code
    <div class="dropdown basalt-dd-multi" data-basalt-dd-multi>
      <button type="button" class="btn btn-outline-secondary dropdown-toggle"
              data-bs-toggle="dropdown" data-bs-auto-close="outside">
        Industries<span class="basalt-dd-multi-count" data-basalt-dd-count>0</span>
      </button>
      <div class="dropdown-menu basalt-dd-multi-menu">
        <label class="dropdown-item basalt-dd-multi-all"><input class="form-check-input" type="checkbox" data-basalt-dd-all>Every industry</label>
        <hr class="dropdown-divider">
        <ul class="basalt-dd-multi-list">
          <li><label class="dropdown-item basalt-dd-multi-option"><input class="form-check-input" type="checkbox" value="Home care">Home care</label></li>
          …
        </ul>
        <div class="basalt-dd-multi-foot">
          <button type="button" class="btn btn-link btn-sm" data-basalt-dd-clear>Clear</button>
          <button type="button" class="btn btn-primary btn-sm" data-basalt-dd-done>Done</button>
        </div>
      </div>
    </div>
    <ul class="basalt-dd-multi-chips" data-basalt-dd-chips aria-label="Chosen industries"></ul>

    Form in menu

    Any form fits in a dropdown-menu. Keep it short: one or two fields and one button.

    Panel
    Show code
    <div class="dropdown">
      <button class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown"
              data-bs-auto-close="outside">Add a discount</button>
      <form class="dropdown-menu p-3">
        <label class="form-label" for="code">Discount code</label>
        <input type="text" class="form-control" id="code">
        <button type="submit" class="btn btn-primary btn-sm w-100 mt-3">Apply code</button>
      </form>
    </div>

    Filter panel

    A dropdown that holds a small form, with a header, a footer and a live count on the apply button. Nothing changes until you apply; Cancel or Escape puts the choices back as they were.

    Panel

    Showing all 124 visits.

    Show code
    <div class="dropdown">
      <button type="button" class="btn btn-outline-secondary dropdown-toggle"
              data-bs-toggle="dropdown" data-bs-auto-close="outside">Filters</button>
      <form class="dropdown-menu basalt-dd-panel">
        <div class="basalt-dd-panel-head">
          <p class="basalt-dd-panel-title">Filter visits</p>
          <button type="button" class="btn btn-link btn-sm">Reset</button>
        </div>
        <div class="basalt-dd-panel-body">
          <fieldset class="basalt-dd-panel-group">
            <legend class="basalt-dd-panel-label">Type</legend>
            …
          </fieldset>
        </div>
        <div class="basalt-dd-panel-foot">
          <button type="button" class="btn btn-outline-secondary btn-sm">Cancel</button>
          <button type="submit" class="btn btn-primary btn-sm">Show 124 visits</button>
        </div>
      </form>
    </div>

    Mega menu

    A wide menu laid out in columns, with a highlight tile beside them. The links are ordinary dropdown items, so the arrow keys and typing a letter still work; on a phone the columns stack.

    Panel
    Show code
    <div class="dropdown-menu basalt-dd-mega">
      <div class="basalt-dd-mega-col">
        <p class="dropdown-header">Clothing</p>
        <ul>
          <li><a class="dropdown-item basalt-dd-item" href="#">
            <span class="basalt-dd-item-icon"><i class="bi bi-snow"></i></span>
            <span class="basalt-dd-item-text">
              <span class="basalt-dd-item-title">Tailoring</span>
              <span class="basalt-dd-item-sub">Blazers, suits and trench coats</span>
            </span>
          </a></li>
        </ul>
      </div>
      <div class="basalt-dd-mega-col">…</div>
      <a class="basalt-dd-mega-feature" href="#">…</a>
    </div>

    Searchable menu

    A menu with a search box on top, for lists too long to scan. The arrow keys go from the box into the list and back; picking someone updates the button and closes the menu.

    Search

    Order #3086 has no packer.

    Show code
    <div class="dropdown basalt-dd-search" data-basalt-dd-search>
      <button type="button" class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown">Packer</button>
      <div class="dropdown-menu basalt-dd-search-menu">
        <div class="basalt-dd-search-field">
          <i class="bi bi-search"></i>
          <input type="search" class="form-control form-control-sm basalt-dd-search-input" aria-label="Find a teammate">
        </div>
        <ul class="basalt-dd-search-list">
          <li><button type="button" class="dropdown-item" data-value="Misty Hull">Misty Hull</button></li>
          …
        </ul>
        <p class="basalt-dd-search-empty" hidden>No match.</p>
      </div>
    </div>
    
    <script>
      menu.addEventListener('basalt:pick', (e) => assign(e.detail.value));
    </script>

    Command menu

    A search box over grouped results: pages, records and actions in one list. Typing narrows it and marks the matches, the arrow keys move through what is left and Enter opens it. Use it inline, or as a dropdown on a button or the / key.

    Search

    As a dropdown

    Try typing

    Nothing opened yet.

    Pages
    OrdersEvery order, newest firstG O
    ProductsClothing, accessories and extras in the storeG P
    CustomersPeople who have ordered from the storeG C
    SubscriptionsMonthly extras and their renewal dates
    Products
    Sculpted Shoulder BlazerClothing, ML-BLAZ, $1,290
    Draped Column GownClothing, ML-GOWN, $2,150
    Tiered Organza DressClothing, ML-ORGZ, $1,680
    Express Delivery PassExtra, ML-PASS, $15/member/month
    Actions
    New orderTake an order by phone or from salesN
    Add a productPut something new in the store
    Export ordersDownload this month as CSV
    Invite a teammateSend an invite by email
    Show code
    <div class="basalt-command" data-basalt-command>
      <div class="basalt-command-search">
        <i class="bi bi-search"></i>
        <input type="text" class="basalt-command-input" role="combobox" aria-expanded="true"
               aria-controls="cmd-list" aria-autocomplete="list" aria-label="Search" placeholder="Search">
      </div>
      <div class="basalt-command-list" id="cmd-list" role="listbox" aria-label="Results">
        <div class="basalt-command-group" role="group" aria-labelledby="cmd-pages">
          <div class="basalt-command-heading" id="cmd-pages">Pages</div>
          <div class="basalt-command-item" role="option" id="cmd-orders" data-value="Orders" data-keywords="sales">
            <span class="basalt-command-icon"><i class="bi bi-receipt"></i></span>
            <span class="basalt-command-text">
              <span class="basalt-command-title">Orders</span>
              <span class="basalt-command-sub">Every order, newest first</span>
            </span>
            <kbd class="basalt-command-kbd">G O</kbd>
          </div>
        </div>
      </div>
      <div class="basalt-command-empty" hidden>Nothing matches.</div>
    </div>
    
    <!-- As a dropdown: put the same block in .dropdown-menu.basalt-command-menu,
         with data-bs-auto-close="outside" on the toggle. -->
    <script>
      cmd.addEventListener('basalt:command', (e) => open(e.detail.value));
    </script>