Dropdowns
Toggle contextual overlays for displaying lists of links and more with the Bootstrap dropdown plugin.
Example
<div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown button </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul></div>
Split button
Similarly, create split button dropdowns with virtually the same markup as single button dropdowns, but with the addition of .dropdown-toggle-split
for proper spacing around the dropdown caret.
We use this extra class to reduce the horizontal padding on either side of the caret by 25% and remove the margin-left that’s added for regular button dropdowns. Those extra changes keep the caret centered in the split button and provide a more appropriately sized hit area next to the main button.
<div class="btn-group"> <button type="button" class="btn btn-danger">Action</button> <button type="button" class="btn btn-danger 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="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="#">Separated link</a></li> </ul></div>
Dark dropdowns
Opt into darker dropdowns to match a dark navbar or custom style by adding .dropdown-menu-dark
onto an existing .dropdown-menu
. No changes are required to the dropdown items.
And putting it to use in a navbar:
<div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton2" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown button </button> <ul class="dropdown-menu dropdown-menu-dark" aria-labelledby="dropdownMenuButton2"> <li><a class="dropdown-item active" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="#">Separated link</a></li> </ul></div>
Directions
<div class="dropdown-center"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownCenterBtn" data-bs-toggle="dropdown" aria-expanded="false"> Centered dropdown </button> <ul class="dropdown-menu" aria-labelledby="dropdownCenterBtn"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul></div>
Dropup
Trigger dropdown menus above elements by adding .dropup
to the parent element.
<ul class="d-flex gap g-3"> <li> <!-- Default dropup button --> <div class="btn-group dropup"> <button type="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="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul> </div> </li> <li> <!-- Split dropup button --> <div class="btn-group dropup"> <button type="button" class="btn btn-secondary"> Split dropup </button> <button type="button" class="btn btn-secondary 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="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul> </div> </li></ul>
Dropup centered
Make the dropup menu centered above the toggle with .dropup-center
on the parent element.
<div class="dropup-center dropup"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropupCenterBtn" data-bs-toggle="dropdown" aria-expanded="false"> Centered dropup </button> <ul class="dropdown-menu" aria-labelledby="dropupCenterBtn"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul></div>
Dropend
Trigger dropdown menus at the right of the elements by adding .dropend
to the parent element.
<ul class="d-flex gap g-3"> <li> <!-- Default dropend button --> <div class="btn-group dropend"> <button type="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="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul> </div> </li> <li> <!-- Split dropend button --> <div class="btn-group dropend"> <button type="button" class="btn btn-secondary"> Split dropend </button> <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false"> <span class="visually-hidden">Toggle Dropend</span> </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul> </div> </li></ul>
Dropstart
Trigger dropdown menus at the left of the elements by adding .dropstart
to the parent element.
<ul class="d-flex gap g-3"> <li> <!-- Default dropend button --> <div class="btn-group dropstart"> <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> Dropstart </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul> </div> </li> <li> <!-- Split dropstart button --> <div class="btn-group dropstart"> <button type="button" class="btn btn-secondary"> Split dropstart </button> <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false"> <span class="visually-hidden">Toggle Dropstart</span> </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Action two</a></li> <li><a class="dropdown-item" href="#">Action three</a></li> </ul> </div> </li> </ul>
Active
Add .active
to items in the dropdown to style them as active.
<div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenu2"> <li><button class="dropdown-item" type="button">Action</button></li> <li><button class="dropdown-item active" href="#" aria-current="true">Another action</button></li> <li><button class="dropdown-item" type="button">Something else here</button></li> </ul></div>
Menu alignment
Add .dropdown-menu-end
to a .dropdown-menu
to right align the dropdown menu.
To align left the dropdown menu with the given breakpoint or larger, add .dropdown-menu-end
and .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-start
.
Right-aligned but left aligned when large screen
<div class="btn-group"> <button type="button" class="btn btn-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> Right-aligned menu example </button> <ul class="dropdown-menu dropdown-menu-end"> <li><button class="dropdown-item" type="button">Action</button></li> <li><button class="dropdown-item" type="button">Another action</button></li> <li><button class="dropdown-item" type="button">Something else here</button></li> </ul></div>
Alignment options
Taking most of the options shown above, here’s a small kitchen sink demo of various dropdown alignment options in one place.
<div class="btn-group"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> </ul></div>
Menu content
Add a header to label sections of actions in any dropdown menu.
Headers
Dividers
Text
<div class="btn-group"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </button> <ul class="dropdown-menu"> <li><h6 class="dropdown-header fw-semibold">Dropdown header</h6></li> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> </ul></div>
Forms
Put a form within a dropdown menu, or make it into a dropdown menu, and use margin or padding utilities to give it the negative space you require.
<div class="dropdown-menu position-static d-block"> <form class="px-4 py-3"> <div class="mb-3"> <label for="exampleDropdownFormEmail1" class="form-label">Email address</label> <input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="email@example.com"> </div> <div class="mb-3"> <label for="exampleDropdownFormPassword1" class="form-label">Password</label> <input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password"> </div> <div class="mb-3"> <div class="form-check form-check-sm"> <input type="checkbox" class="form-check-input" id="dropdownCheck"> <label class="form-check-label" for="dropdownCheck"> Remember me </label> </div> </div> <button type="submit" class="btn btn-primary">Sign in</button> </form> <div class="dropdown-divider"></div> <a class="dropdown-item" href="#">New around here? Sign up</a> <a class="dropdown-item" href="#">Forgot password?</a></div>
Dropdown options
Use data-bs-offset
or data-bs-reference
to change the location of the dropdown.
<ul class="d-flex flex-wrap gap g-3"> <li> <div class="dropdown"> <button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuOffset" data-bs-toggle="dropdown" aria-expanded="false" data-bs-offset="10,20"> Offset </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuOffset"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> </ul> </div> </li> <li> <div class="btn-group"> <button type="button" class="btn btn-secondary">Reference</button> <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" id="dropdownMenuReference" data-bs-toggle="dropdown" aria-expanded="false" data-bs-reference="parent"> <span class="visually-hidden">Toggle Dropdown</span> </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuReference"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> <li><a class="dropdown-item" href="#">Something else here</a></li> <li><hr class="dropdown-divider"></li> <li><a class="dropdown-item" href="#">Separated link</a></li> </ul> </div> </li></ul>
Auto close behavior
By default, the dropdown menu is closed when clicking inside or outside the dropdown menu. You can use the autoClose
option to change this behavior of the dropdown.
<ul class="d-flex flex-wrap gap g-3"> <li> <div class="btn-group"> <button class="btn btn-secondary dropdown-toggle" type="button" id="defaultDropdown" data-bs-toggle="dropdown" data-bs-auto-close="true" aria-expanded="false"> Default dropdown </button> <ul class="dropdown-menu" aria-labelledby="defaultDropdown"> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> </ul> </div> </li> <li> <div class="btn-group"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuClickableOutside" data-bs-toggle="dropdown" data-bs-auto-close="inside" aria-expanded="false"> Clickable outside </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuClickableOutside"> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> </ul> </div> </li> <li> <div class="btn-group"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuClickableInside" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-expanded="false"> Clickable inside </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuClickableInside"> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> </ul> </div> </li> <li> <div class="btn-group"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuClickable" data-bs-toggle="dropdown" data-bs-auto-close="false" aria-expanded="false"> Manual close </button> <ul class="dropdown-menu" aria-labelledby="dropdownMenuClickable"> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> <li><a class="dropdown-item" href="#">Menu item</a></li> </ul> </div> </li> </ul>