A dropdown button next to a text field is a compact way to let users pick an option that applies to what they type: a search scope, a unit, a currency. In Bootstrap 5.3 the dropdown sits directly inside an .input-group, with no wrapper element and no jQuery.
Page setup
Dropdowns are positioned by Popper, which is included in bootstrap.bundle.min.js. The plain bootstrap.min.js does not contain it, and the menu will not open.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap input with dropdown</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<main class="container py-4">
<!-- input group goes here -->
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Dropdown before the input
<form>
<div class="input-group mb-3">
<button class="btn btn-outline-secondary dropdown-toggle" type="button"
data-bs-toggle="dropdown" aria-expanded="false">Action</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>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="#">Separated link</a></li>
</ul>
<input type="text" class="form-control" aria-label="Text input with dropdown button">
</div>
</form>
Several pieces of the Bootstrap 3 version changed:
- The
<div class="input-group-btn">wrapper is gone. The button and menu are direct children of.input-group. data-toggle="dropdown"is nowdata-bs-toggle="dropdown". The old attribute is ignored and the button does nothing.- The
<span class="caret"></span>is no longer needed..dropdown-toggledraws the arrow itself with a CSS pseudo-element. - Menu items need
.dropdown-item, and the divider is<li><hr class="dropdown-divider"></li>instead of<li class="divider">. .btn-defaultwas removed;.btn-outline-secondarylooks closest.
Bootstrap sets aria-expanded on the button as the menu opens and closes, and the menu can be used with the keyboard: arrow keys move between items and Escape closes it.
Dropdown after the input
Put the button and menu after the input and add .dropdown-menu-end, so the menu lines up with the right edge instead of hanging off the side of the page:
<div class="input-group mb-3">
<input type="text" class="form-control" aria-label="Text input with dropdown button">
<button class="btn btn-outline-secondary dropdown-toggle" type="button"
data-bs-toggle="dropdown" aria-expanded="false">Options</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>
Making the menu pick a value
The examples above only show a menu. In a real form, choosing an item should change something. Here the dropdown selects what to search in, updates its own label, and writes the choice into a hidden field that is submitted with the form:
<form action="/search" method="get">
<input type="hidden" name="scope" value="all">
<div class="input-group" id="search-group">
<button class="btn btn-outline-secondary dropdown-toggle" type="button"
data-bs-toggle="dropdown" aria-expanded="false">All</button>
<ul class="dropdown-menu">
<li><button class="dropdown-item" type="button" data-value="all">All</button></li>
<li><button class="dropdown-item" type="button" data-value="posts">Posts</button></li>
<li><button class="dropdown-item" type="button" data-value="code">Code samples</button></li>
</ul>
<input type="search" name="q" class="form-control" placeholder="Search..." aria-label="Search">
<button class="btn btn-primary" type="submit">Go</button>
</div>
</form>
const group = document.getElementById('search-group');
const toggle = group.querySelector('.dropdown-toggle');
const scope = group.closest('form').elements.scope;
group.querySelectorAll('.dropdown-item').forEach(item => {
item.addEventListener('click', () => {
scope.value = item.dataset.value;
toggle.textContent = item.textContent;
});
});
The menu items are <button type="button"> elements rather than links. They are actions, not navigation, and without type="button" a click would submit the form. Bootstrap closes the menu after the click by itself.
When a plain select is better
If the dropdown only chooses a value, a native <select> inside the input group does the same job with no script:
<div class="input-group">
<select class="form-select flex-grow-0 w-auto" name="scope" aria-label="Search in">
<option value="all" selected>All</option>
<option value="posts">Posts</option>
<option value="code">Code samples</option>
</select>
<input type="search" name="q" class="form-control" placeholder="Search..." aria-label="Search">
<button class="btn btn-primary" type="submit">Go</button>
</div>
.w-auto and .flex-grow-0 stop the select from taking half the width. A native select works without JavaScript, posts its value automatically, binds to a model property in ASP.NET Core with asp-for, and opens the platform’s own picker on phones. Keep the Bootstrap dropdown for menus that run actions or need richer content than an <option> can hold.
Related examples
- Bootstrap input groups
- Bootstrap form validation states
- Bootstrap tooltips
- Dropdowns in the Bootstrap documentation