An input group attaches text, icons, checkboxes or buttons to the side of a text field, so they look like one control: a $ before a price, .00 after it, a “Go” button at the end of a search box. Input groups are pure CSS and need no JavaScript.
Page setup
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap input groups</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
</head>
<body>
<main class="container py-4">
<!-- forms go here -->
</main>
</body>
</html>
The second stylesheet is Bootstrap Icons. Glyphicons were dropped in Bootstrap 4, and Bootstrap Icons is the official replacement. Leave it out if you do not use icons.
Text and icon add-ons
<form>
<div class="row g-3">
<div class="col-md-4">
<div class="input-group">
<span class="input-group-text" id="username-addon">
<i class="bi bi-person" aria-hidden="true"></i>
</span>
<input type="text" class="form-control" placeholder="Username"
aria-label="Username" aria-describedby="username-addon">
</div>
</div>
<div class="col-md-4">
<div class="input-group">
<input type="text" class="form-control" placeholder="Amount"
aria-label="Amount (to the nearest dollar)" inputmode="numeric">
<span class="input-group-text">.00</span>
</div>
</div>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-text">$</span>
<input type="text" class="form-control" placeholder="US dollars"
aria-label="Amount in US dollars" inputmode="numeric">
<span class="input-group-text">.00</span>
</div>
</div>
</div>
</form>
.input-group-addon from Bootstrap 3 is now .input-group-text. The grid classes changed too: .col-xs-4 no longer exists, because the smallest breakpoint has no infix in Bootstrap 4 and 5. .col-4 gives you three columns at every width; .col-md-4, as above, stacks the fields on phones and puts them side by side from 768 pixels up. .g-3 on the row adds spacing between the columns and between the stacked rows.
Checkboxes and radios
<form>
<div class="row g-3">
<div class="col-md-6">
<div class="input-group">
<div class="input-group-text">
<input class="form-check-input mt-0" type="checkbox" value=""
aria-label="Checkbox for following text input">
</div>
<input type="text" class="form-control" aria-label="Text input with checkbox">
</div>
</div>
<div class="col-md-6">
<div class="input-group">
<div class="input-group-text">
<input class="form-check-input mt-0" type="radio" value=""
aria-label="Radio button for following text input">
</div>
<input type="text" class="form-control" aria-label="Text input with radio button">
</div>
</div>
</div>
</form>
.form-check-input gives the checkbox Bootstrap’s styling, and .mt-0 removes the small top margin it normally has, which would push it off-center inside the add-on.
Buttons
<form>
<div class="row g-3">
<div class="col-md-6">
<div class="input-group">
<input type="search" class="form-control" placeholder="Search..." aria-label="Search">
<button class="btn btn-outline-secondary" type="submit">Go</button>
</div>
</div>
<div class="col-md-6">
<div class="input-group">
<button class="btn btn-outline-secondary" type="button">Action</button>
<button class="btn btn-outline-secondary" type="button">Options</button>
<input type="text" class="form-control" placeholder="Type something..."
aria-label="Text input with two buttons">
</div>
</div>
</div>
</form>
The .input-group-btn wrapper was removed in Bootstrap 4. Buttons are now direct children of .input-group, next to the input. .btn-default is gone as well; .btn-outline-secondary is the closest match to the old grey button.
Things to watch
A placeholder is not a label. It disappears as soon as the user types, and some screen readers skip it. Every input above has an aria-label. In a real form a visible <label class="form-label"> above the group is better still; put it outside the .input-group element, or it becomes part of the group.
Wrapping. Bootstrap 5 input groups wrap onto a second line when there is not enough room, which can split a button from its field on narrow screens. Add .flex-nowrap to the .input-group to keep everything on one line.
Sizing. Put .input-group-sm or .input-group-lg on the group, not on the individual input. The add-ons and buttons then size with it.
Validation. If you show validation feedback inside an input group, add .has-validation to the group. Without it the last element loses its rounded corners when the feedback message follows it. See form validation states for the full markup.
Decimal input and ASP.NET Core. type="number" always submits a dot as the decimal separator, whatever the user’s locale. ASP.NET Core binds form fields using the current request culture, so on a site configured for, say, Turkish or German, 12.50 can bind to 1250. Either bind amounts with the invariant culture or use a text input and parse it yourself.
Related examples
- Bootstrap input with dropdown button
- Bootstrap form validation states
- Bootstrap horizontal login form
- Bootstrap vertical login form
- Input group in the Bootstrap documentation