Ask any question about Bootstrap here... and get an instant response.
Post this Question & Answer:
How can I toggle a Bootstrap dropdown using data-bs attributes without any JavaScript?
Asked on Jan 08, 2026
Answer
In Bootstrap 5, you can toggle a dropdown using the `data-bs-toggle` attribute without writing any JavaScript. This is done by setting `data-bs-toggle` to "dropdown" on the button or link that will trigger the dropdown menu.
<!-- BEGIN COPY / PASTE -->
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<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>
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with Bootstrap 5 best practices.- The `data-bs-toggle="dropdown"` attribute is used to enable the dropdown functionality.
- The `aria-expanded` attribute is used to indicate the current state of the dropdown (true or false).
- The `aria-labelledby` attribute on the `
- ` element links it to the button, improving accessibility.
- Ensure you have included Bootstrap's CSS and JS files in your project for this to work.
Recommended Links:
