Dropdowns
Dropdowns reveal a menu of links when a button is clicked.
In this page:
Syntax
<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
<!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
- Missing data-bs-toggle
- Forgetting the JS bundle
- 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: