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.
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>
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>
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.
Strengthen your responsive web design mastery by studying these connected classes:
Incorporate dropdown menus into main site navigation headers.
Create dual-action buttons with independent click and toggle triggers.
Learn how Popper.js calculates coordinates, flips, and boundary offsets.
Use .dropdown-menu-dark for high-contrast dark dropdown menus.
bootstrap.bundle.min.js (which includes Popper.js) and verify that the trigger button contains the attribute data-bs-toggle='dropdown'.
.dropdown-menu-dark class to the <ul class='dropdown-menu dropdown-menu-dark'> element.
data-bs-auto-close='outside' or data-bs-auto-close='false' to the trigger button.
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