Dropdown menus help users pick options easily. Changing their direction makes sure they fit well on the screen and stay visible.
Dropdown directions (up, left, right) in Bootsrap
<div class="dropdown dropup"> <button class="btn btn-secondary dropdown-toggle" type="button" 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="#">Another action</a></li> </ul> </div>
Use dropup class to make dropdown open upwards.
Use dropstart for left direction and dropend for right direction.
<div class="dropdown dropup"> <button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropup </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Option 1</a></li> <li><a class="dropdown-item" href="#">Option 2</a></li> </ul> </div>
<div class="dropdown dropstart"> <button class="btn btn-success dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropstart </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Left 1</a></li> <li><a class="dropdown-item" href="#">Left 2</a></li> </ul> </div>
<div class="dropdown dropend"> <button class="btn btn-warning dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropend </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Right 1</a></li> <li><a class="dropdown-item" href="#">Right 2</a></li> </ul> </div>
This page shows three dropdown buttons. Each opens in a different direction: up, left, and right. This helps you see how to control dropdown placement using Bootstrap classes.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Bootstrap Dropdown Directions</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body class="p-4"> <h2>Dropdown Directions Example</h2> <div class="mb-3"> <div class="dropdown dropup"> <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropup </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Action 1</a></li> <li><a class="dropdown-item" href="#">Action 2</a></li> </ul> </div> </div> <div class="mb-3"> <div class="dropdown dropstart"> <button class="btn btn-success dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropstart </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Left 1</a></li> <li><a class="dropdown-item" href="#">Left 2</a></li> </ul> </div> </div> <div class="mb-3"> <div class="dropdown dropend"> <button class="btn btn-warning dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropend </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Right 1</a></li> <li><a class="dropdown-item" href="#">Right 2</a></li> </ul> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Make sure to include Bootstrap's JavaScript bundle for dropdowns to work.
Use aria-expanded and other ARIA attributes for accessibility.
Dropdown direction classes help keep menus visible and improve user experience.
Use dropup, dropstart, and dropend classes to control dropdown direction.
Adjust dropdown direction to fit your page layout and avoid clipping.
Always include Bootstrap JS and ARIA attributes for proper functionality and accessibility.
Practice
Solution
Step 1: Understand dropdown direction classes
Bootstrap provides specific classes to control dropdown direction:dropupfor up,dropstartfor left, anddropendfor right.Step 2: Identify the class for upward dropdown
The classdropupis used to make the dropdown open upwards.Final Answer:
<code>dropup</code> -> Option AQuick Check:
Upward dropdown = dropup [OK]
- Confusing dropstart or dropend with upward direction
- Using non-existent class dropdown-up
- Forgetting to add the class to the dropdown container
Solution
Step 1: Identify the class for left-opening dropdown
Bootstrap usesdropstartto make dropdowns open to the left side.Step 2: Check the HTML structure
The dropdown container must have bothdropdownanddropstartclasses. The button triggers the dropdown withdata-bs-toggle="dropdown"and the menu is insideul.dropdown-menu.Final Answer:
HTML with class dropstart -> Option BQuick Check:
Left dropdown = dropstart class [OK]
- Using dropend or dropup instead of dropstart
- Missing data-bs-toggle attribute on button
- Using non-Bootstrap class like dropdown-left
<div class="dropdown dropend">
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Right Menu
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Item 1</a></li>
</ul>
</div>Solution
Step 1: Understand the dropend class effect
The classdropendmakes the dropdown menu open to the right side of the button.Step 2: Analyze the code snippet
The dropdown container hasdropdown dropendclasses, so the menu will appear on the right side when triggered.Final Answer:
The dropdown opens to the right -> Option DQuick Check:
dropend means right direction [OK]
- Assuming dropend means down or up
- Confusing dropend with dropstart
- Ignoring the class on the dropdown container
Solution
Step 1: Identify how to control dropdown direction
Bootstrap uses specific classes likedropupto change dropdown direction upwards.Step 2: Fix the dropdown by adding the correct class
Addingdropupto the dropdown container changes the menu to open upwards. Other options either break functionality or are invalid.Final Answer:
Add the class dropup to the dropdown container div -> Option AQuick Check:
Use dropup class for upward dropdown [OK]
- Changing button type instead of container class
- Removing dropdown-menu class breaks styling
- Using non-existent data attribute for direction
Solution
Step 1: Understand responsive dropdown direction control
Bootstrap's direction classes likedropstartcontrol dropdown direction but are not responsive by default.Step 2: Use CSS media queries to adjust classes
Applyingdropstartfor large screens and removing or overriding it on small screens with media queries allows the dropdown to open left on large and default down on small screens.Final Answer:
Use dropstart class and override it with media queries on small screens -> Option CQuick Check:
Responsive direction needs CSS override [OK]
- Relying only on Bootstrap classes without CSS overrides
- Using JavaScript unnecessarily for simple CSS control
- Misusing dropdown-menu-end which only aligns menu horizontally
Ready to prove it?
Pass the test and this pattern moves unknown
