How can I group inputs and buttons with input-group for search bars?
Asked on Jul 09, 2025
1 Answer
To create a search bar using Bootstrap's input group, you can combine an input field with a button inside a `.input-group` container. This allows you to create a cohesive search bar component.
<!-- BEGIN COPY / PASTE -->
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-secondary" type="button">Search</button>
</div>
<!-- END COPY / PASTE -->
Additional Comment:
✅ Answered with Bootstrap 5 best practices.- The `.input-group` class is used to wrap the input and button together.
- The `form-control` class is applied to the input for styling.
- The `btn` and `btn-outline-secondary` classes style the button.
- Use `aria-label` for accessibility, describing the input's purpose.