Bootstrap dropdowns are a versatile way to add interactive menus to your web application. With just a few classes, Bootstrap provides a ready-to-use dropdown component that can be used in navigation, forms, or anywhere else where you need a list of selectable options.
Dropdowns are toggleable, contextual overlays for displaying lists of links and more. They’re made interactive with the included Bootstrap dropdown JavaScript plugin.
Dropdowns are built on a third party library, Popper.js, which provides dynamic positioning and viewport detection
To create a dropdown, you need a div with the class dropdown, a button or link with dropdown-toggle, and a div with the dropdown-menu class for the dropdown items.
Example:
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</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>
</ul>
</div>
The .dropdown class indicates a dropdown menu.
To open the dropdown menu, use a button or a link with a class of .dropdown-toggle and the data-bs-toggle="dropdown" attribute.
Add the .dropdown-menu class to a container element, like <div> or <ul>, to actually build the dropdown menu. Then add the .dropdown-item class to each element (links or buttons) inside the dropdown menu.
The .dropdown-divider class is used to separate links inside the dropdown menu with a thin horizontal border:
Example:
<li><hr class="dropdown-divider"></hr></li>
The .dropdown-header class is used to add headers inside the dropdown menu:
<li><h4 class="dropdown-header">Dropdown header 1</h4></li>
Highlight a specific dropdown item with the .active class (adds a blue background color).
To disable an item in the dropdown menu, use the .disabled class (gets a light-grey text color and a "no-parking-sign" icon on hover):
Example:
<li><a class="dropdown-item" href="#">Normal</a></li>
<li><a class="dropdown-item active" href="#">Active</a></li>
<li><a class="dropdown-item disabled" href="#">Disabled</a></li>
You can also create a "dropend" or "dropstart" menu, by adding the .dropend or .dropstart class to the dropdown element. Note that the caret/arrow is added automatically:
Dropright:
<div class="dropdown dropend">
Dropleft:
<div class="dropdown dropstart">
To right-align the dropdown menu, add the .dropdown-menu-end class to the element with .dropdown-menu:
Example:
<div class="dropdown-menu dropdown-menu-end">
If you want the dropdown menu to expand upwards instead of downwards, change the <div> element with class="dropdown" to "dropup":
Example:
<div class="dropup">
The .dropdown-item-text class is used to add plain text to a dropdown item, or used on links for default link styling.
Example:
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Link 1</a></li>
<li><a class="dropdown-item" href="#">Link 2</a></li>
<li><a class="dropdown-item" href="#">Link 3</a></li>
<li><a class="dropdown-item-text" href="#"<Text Link</a></li>
<li><span class="dropdown-item-text">Just Text</span></li>
</ul>