By default, Bootstrap aligns dropdown menus so their left edge matches the left edge of the toggle button. This means the menu opens downward and left-aligned.
In Bootstrap 5, the class dropdown-menu-end aligns the dropdown menu to the right edge of its parent toggle button.
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Menu
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
</ul>
</div>Where will the dropdown menu appear relative to the button when clicked?
<div class="dropdown"> <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Menu </button> <ul class="dropdown-menu dropdown-menu-end"> <li><a class="dropdown-item" href="#">Action</a></li> <li><a class="dropdown-item" href="#">Another action</a></li> </ul> </div>
The class dropdown-menu-end makes the dropdown menu open below the button but aligned to the right edge.
The selector .dropdown-menu.dropdown-menu-end targets elements with both classes, which are the right-aligned dropdown menus.
The aria-expanded attribute on the toggle button changes dynamically to indicate if the dropdown menu is open (true) or closed (false), helping screen readers understand the state.
