← Back to Bootstrap Course | Chapter 6: Components — Navigation | Lesson 4 of 7

Dropdowns

Dropdowns reveal a menu of links when a button is clicked.

In this page:

  1. Dropdowns
Syntax
markup
<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown">Menu</button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Item</a></li>
  </ul>
</div>

Dropdowns

Wrap a trigger with data-bs-toggle="dropdown" and a .dropdown-menu list in .dropdown. Directions can be changed with .dropup, .dropend or .dropstart, and alignment with .dropdown-menu-end.

Items use .dropdown-item, and dividers and headers organise them.

Requires the JS bundle with Popper.

Note: The dropdown works without extra JavaScript code, only the bundle.

Example: Dropdowns

markup
<!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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body class="p-3">
<div class="container">
  <div class="dropdown">
    <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Actions</button>
    <ul class="dropdown-menu">
      <li><h6 class="dropdown-header">Edit</h6></li>
      <li><a class="dropdown-item" href="#">Rename</a></li>
      <li><a class="dropdown-item" href="#">Duplicate</a></li>
      <li><hr class="dropdown-divider"></li>
      <li><a class="dropdown-item text-danger" href="#">Delete</a></li>
    </ul>
  </div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Missing data-bs-toggle
  2. Forgetting the JS bundle
  3. Placing the menu outside the dropdown wrapper
Chapter Summary
  • data-bs-toggle="dropdown" on the trigger
  • dropdown-menu and dropdown-item
  • dropup, dropend, dropstart
  • Needs the JS bundle
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.