TExcelTAD
Home › Bootstrap › BS5 Dropdowns

Bootstrap 5 Dropdowns

A dropdown is a toggleable menu of links or actions that opens below (or beside) a button. Dropdowns need Bootstrap's JavaScript bundle, which includes Popper to position the menu so it stays on screen.

A basic dropdown

Three parts: a wrapper with .dropdown, a toggle button with .dropdown-toggle and data-bs-toggle="dropdown", and a .dropdown-menu list containing .dropdown-items.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="dropdown">
    <button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
      Account
    </button>
    <ul class="dropdown-menu">
      <li><h6 class="dropdown-header">Signed in as Ana</h6></li>
      <li><a class="dropdown-item" href="#">Profile</a></li>
      <li><a class="dropdown-item active" href="#" aria-current="true">Settings</a></li>
      <li><a class="dropdown-item disabled" aria-disabled="true">Billing</a></li>
      <li><hr class="dropdown-divider"></li>
      <li><button class="dropdown-item text-danger" type="button">Sign out</button></li>
    </ul>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Close it by clicking outside, pressing Esc or choosing an item. Arrow keys move between items.

Menu contents

Class Purpose
.dropdown-item A clickable entry (<a> or <button>)
.dropdown-header Non-clickable section title
.dropdown-divider Horizontal separator (on an <hr>)
.dropdown-item-text Plain, non-interactive text
.active / .disabled Highlighted / unusable item
.dropdown-menu-dark Dark menu (5.3 prefers data-bs-theme="dark" on the menu)

Direction and alignment

Change where the menu opens by changing the wrapper class, and align it with .dropdown-menu-end.

Wrapper class Opens
.dropdown Down (default)
.dropup Up
.dropend To the right
.dropstart To the left
.dropdown-center / .dropup-center Centred under/over the toggle
html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="d-flex flex-wrap gap-2 pt-5 justify-content-center">
    <div class="dropup">
      <button class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Dropup</button>
      <ul class="dropdown-menu"><li><a class="dropdown-item" href="#">Up here</a></li></ul>
    </div>
    <div class="dropend">
      <button class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Dropend</button>
      <ul class="dropdown-menu"><li><a class="dropdown-item" href="#">To the right</a></li></ul>
    </div>
    <div class="dropdown">
      <button class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Right-aligned</button>
      <ul class="dropdown-menu dropdown-menu-end"><li><a class="dropdown-item" href="#">Aligned to the end</a></li></ul>
    </div>
    <div class="dropdown" data-bs-theme="dark">
      <button class="btn btn-dark dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Dark menu</button>
      <ul class="dropdown-menu">
        <li><a class="dropdown-item" href="#">One</a></li>
        <li><a class="dropdown-item" href="#">Two</a></li>
      </ul>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Note: Popper flips a menu to the other side when there isn't room. In the short preview frame a "down" menu may open upwards — drag the frame's bottom-right corner to make it taller.

Split buttons

A split button has a main action and a separate caret for more options. Use .dropdown-toggle-split on the caret button inside a .btn-group, with hidden text for screen readers.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="btn-group">
    <button type="button" class="btn btn-success" onclick="console.log('Saved')">Save</button>
    <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
      <span class="visually-hidden">More save options</span>
    </button>
    <ul class="dropdown-menu">
      <li><a class="dropdown-item" href="#">Save as…</a></li>
      <li><a class="dropdown-item" href="#">Save a copy</a></li>
    </ul>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Events and JavaScript

You can control dropdowns from JavaScript and react to events such as show.bs.dropdown and hidden.bs.dropdown.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="dropdown d-inline-block">
    <button id="lang" class="btn btn-outline-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">Language</button>
    <ul class="dropdown-menu" id="langMenu">
      <li><button class="dropdown-item" type="button">English</button></li>
      <li><button class="dropdown-item" type="button">Tiếng Việt</button></li>
      <li><button class="dropdown-item" type="button">Español</button></li>
    </ul>
  </div>
  <button class="btn btn-link" id="open">Open from JS</button>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  <script>
    const toggle = document.getElementById('lang');
    const dd = bootstrap.Dropdown.getOrCreateInstance(toggle);
    document.getElementById('open').addEventListener('click', (e) => { e.stopPropagation(); dd.show(); });
    toggle.addEventListener('hidden.bs.dropdown', () => console.log('menu closed'));
    document.getElementById('langMenu').addEventListener('click', (e) => {
      if (e.target.matches('.dropdown-item')) {
        toggle.textContent = e.target.textContent;
        console.log('chosen:', e.target.textContent);
      }
    });
  </script>
</body>
</html>

Tip: Use data-bs-auto-close="outside" (or "inside", "false") on the toggle to control when the menu closes — e.g. keep it open while the user fills a small form inside the menu.

Test yourself

Which attribute makes a button open a dropdown menu?

  1. data-bs-toggle="dropdown"
  2. data-bs-target="menu"
  3. data-dropdown="true"
  4. role="menu"

Which wrapper class makes a menu open upwards?

  1. .dropdown-up
  2. .dropup
  3. .dropdown-top
  4. .dropstart

What does Popper do for dropdowns?

  1. Adds animations
  2. Positions the menu and flips it if there isn't room
  3. Loads the CSS
  4. Adds keyboard support