Class 23 of 48 • Core Components

Bootstrap 5 Dropdowns: Triggers, Directions & Popper.js Integration

Dropdowns are contextual overlay menus used for displaying lists of navigational links and actions. In Bootstrap 5, dropdown positioning is powered by Popper.js v2, which dynamically calculates screen boundaries to prevent dropdowns from clipping offscreen.

Bootstrap 5 Popper.js Powered Dropdowns and Split Menus
Figure 23: Dropdown menu positioning engine powered by Popper.js with auto-flipping, dropup, and split action buttons.

1. Basic Dropdown Menu

A dropdown requires a container with .dropdown, a trigger button with data-bs-toggle="dropdown", and a companion .dropdown-menu:

<div class="dropdown">
  <button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
    Select Technology
  </button>
  <ul class="dropdown-menu">
    <li><h6 class="dropdown-header">Front-End</h6></li>
    <li><a class="dropdown-item" href="../bootstrap/">Bootstrap 5</a></li>
    <li><a class="dropdown-item" href="../react/">React JS</a></li>
    <li><hr class="dropdown-divider"></li>
    <li><h6 class="dropdown-header">Back-End</h6></li>
    <li><a class="dropdown-item" href="../nodejs/">Node.js</a></li>
  </ul>
</div>

2. Split Button Dropdowns

Create dual-action buttons where clicking the main label triggers a primary action, while clicking the arrow toggles the dropdown menu:

<div class="btn-group">
  <button type="button" class="btn btn-success">Save Document</button>
  <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
    <span class="visually-hidden">Toggle Dropdown</span>
  </button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Save as PDF</a></li>
    <li><a class="dropdown-item" href="#">Export as CSV</a></li>
  </ul>
</div>

3. Dropdown Directions (dropup, dropend, dropstart)

Direct where the dropdown menu opens relative to its button:

     .dropup: Opens menu upwards above the trigger button.

     .dropend: Opens menu to the right of the button.

     .dropstart: Opens menu to the left of the button.

Explore Related Bootstrap Tutorials & Next Steps

Strengthen your responsive web design mastery by studying these connected classes:

Navbars with Dropdowns

Incorporate dropdown menus into main site navigation headers.

Split Button Dropdowns

Create dual-action buttons with independent click and toggle triggers.

Popper.js Positioning & Events

Learn how Popper.js calculates coordinates, flips, and boundary offsets.

Dark Dropdown Menus

Use .dropdown-menu-dark for high-contrast dark dropdown menus.

Frequently Asked Questions (FAQ) - Student & Interview Review

Ensure you linked bootstrap.bundle.min.js (which includes Popper.js) and verify that the trigger button contains the attribute data-bs-toggle='dropdown'.
Add the .dropdown-menu-dark class to the <ul class='dropdown-menu dropdown-menu-dark'> element.
Add data-bs-auto-close='outside' or data-bs-auto-close='false' to the trigger button.

Next Step in Your Bootstrap Learning Path:

Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.

Continue to Class 24: Alerts & Notifications → Previous: ← Class 22: Cards & Grid Layouts | Full Syllabus

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Reddit

You may also like this!