Toggle contextual overlays for displaying lists of links and more with the Bootstrap dropdown plugin.
Examples
Wrap the dropdown’s toggle (your button or link) and the dropdown menu within .dropdown, or another element that declares position: relative;. Dropdowns can be triggered from <a> or <button> elements to better fit your potential needs. The examples shown here use semantic <ul> elements where appropriate, but custom markup is supported.
Single button
Any single .btn can be turned into a dropdown toggle with some markup changes. Here’s how you can put them to work with either <button> elements:
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.
By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add .dropdown-menu-end to a .dropdown-menu to right align the dropdown menu. Directions are mirrored when using Bootstrap in RTL, meaning .dropdown-menu-end will appear on the left side.
<divclass="btn-group"><buttontype="button"class="btn btn-secondary dropdown-toggle"data-bs-toggle="dropdown"aria-expanded="false">
Right-aligned menu example
</button><ulclass="dropdown-menu dropdown-menu-end"><li><buttonclass="dropdown-item"type="button">Action</button></li><li><buttonclass="dropdown-item"type="button">Another action</button></li><li><buttonclass="dropdown-item"type="button">Something else here</button></li></ul></div>
Responsive alignment
If you want to use responsive alignment, disable dynamic positioning by adding the data-bs-display="static" attribute and use the responsive variation classes.
To align right the dropdown menu with the given breakpoint or larger, add .dropdown-menu{-sm|-md|-lg|-xl|-xxl}-end.
<divclass="btn-group"><buttontype="button"class="btn btn-secondary dropdown-toggle"data-bs-toggle="dropdown"data-bs-display="static"aria-expanded="false">
Left-aligned but right aligned when large screen
</button><ulclass="dropdown-menu dropdown-menu-lg-end"><li><buttonclass="dropdown-item"type="button">Action</button></li><li><buttonclass="dropdown-item"type="button">Another action</button></li><li><buttonclass="dropdown-item"type="button">Something else here</button></li></ul></div>
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.
<divclass="btn-group"><buttontype="button"class="btn btn-secondary dropdown-toggle"data-bs-toggle="dropdown"data-bs-display="static"aria-expanded="false">
Right-aligned but left aligned when large screen
</button><ulclass="dropdown-menu dropdown-menu-end dropdown-menu-lg-start"><li><buttonclass="dropdown-item"type="button">Action</button></li><li><buttonclass="dropdown-item"type="button">Another action</button></li><li><buttonclass="dropdown-item"type="button">Something else here</button></li></ul></div>
Note that you don’t need to add a data-bs-display="static" attribute to dropdown buttons in navbars, since Popper isn’t used in navbars.
Menu content
Headers
Add a header to label sections of actions in any dropdown menu.
Place any freeform text within a dropdown menu with text and use spacing utilities. Note that you’ll likely need additional sizing styles to constrain the menu width.
Some example text that's free-flowing within the dropdown menu.
And this is more example text.
<divclass="dropdown-menu p-4 text-muted"style="max-width: 200px;"><p>Some example text that's free-flowing within the dropdown menu. </p><pclass="mb-0">And this is more example text. </p></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.