Bootstrap Input Groups
Bootstrap Input Groups allow us to combine text, buttons, icons, labels and input controls into a single form component.
What is an Input Group?
An Input Group combines an input control with another element such as text, a button or a label.
Bootstrap uses the .input-group class as the main container.
Common uses include:
- Currency inputs
- Website URLs
- Email addresses
- Search boxes
- Username fields
- Quantity inputs
- Input fields with action buttons
Basic Input Group
The simplest Input Group combines text with an input.
Example
<div class="input-group">
<span class="input-group-text">
@
</span>
<input type="text"
class="form-control"
placeholder="Username">
</div>
Output
Text Before Input
We can place text before an input using .input-group-text.
Example
<div class="input-group">
<span class="input-group-text">
₹
</span>
<input type="number"
class="form-control"
placeholder="Amount">
</div>
Output
Text After Input
Text can also be placed after the input field.
Example
<div class="input-group">
<input type="text"
class="form-control">
<span class="input-group-text">
.com
</span>
</div>
Output
Text Before and After Input
Bootstrap allows us to place content on both sides of an input field.
Example
<div class="input-group">
<span class="input-group-text">
₹
</span>
<input type="number"
class="form-control">
<span class="input-group-text">
INR
</span>
</div>
Output
Input Group with Button
An Input Group can contain a Bootstrap button. This is very useful for search boxes and actions.
Example
<div class="input-group">
<input type="text"
class="form-control"
placeholder="Search">
<button class="btn btn-primary">
Search
</button>
</div>
Output
Input Group with Dropdown
A dropdown button can also be combined with an input field.
Example
<div class="input-group">
<button class="btn btn-primary dropdown-toggle"
type="button"
data-bs-toggle="dropdown">
Course
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="#">
.NET
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Java
</a>
</li>
</ul>
<input type="text"
class="form-control">
</div>
Output
Checkbox with Input Group
Checkboxes can also be placed inside an Input Group.
Example
<div class="input-group">
<div class="input-group-text">
<input class="form-check-input mt-0"
type="checkbox">
</div>
<input type="text"
class="form-control"
placeholder="Select option">
</div>
Output
Radio Button with Input Group
A radio button can also be placed before an input field when the user needs to choose one option.
Example
<div class="input-group">
<div class="input-group-text">
<input class="form-check-input mt-0"
type="radio"
name="payment">
</div>
<input type="text"
class="form-control"
placeholder="Payment Details">
</div>
Output
Input Group Sizing
Bootstrap provides three sizes for Input Groups:
- .input-group-sm - Small
- .input-group - Normal
- .input-group-lg - Large
Large Input Group
<div class="input-group input-group-lg">
<span class="input-group-text">
@
</span>
<input type="text"
class="form-control">
</div>
Output
Normal Input Group
Small Input Group
Multiple Input Group Elements
An Input Group can contain multiple text elements and inputs.
Example
<div class="input-group">
<span class="input-group-text">
First Name
</span>
<input type="text"
class="form-control">
<span class="input-group-text">
Last Name
</span>
<input type="text"
class="form-control">
</div>
Output
Search Input Group
Input Groups are commonly used for creating search boxes.
Example
<div class="input-group">
<input type="search"
class="form-control"
placeholder="Search courses">
<button class="btn btn-primary"
type="button">
Search
</button>
</div>
Output
CIIT Training Institute Example
Let's create some practical Input Groups that can be used on a CIIT Training Institute website.
Student Username
Course Fee
Website
Search Course
Important Input Group Classes
| Class | Purpose |
|---|---|
.input-group |
Creates the main Input Group container |
.input-group-text |
Adds text before or after an input |
.input-group-sm |
Creates a small Input Group |
.input-group-lg |
Creates a large Input Group |
.form-control |
Styles the input control |
.btn |
Adds a Bootstrap button |
.dropdown-toggle |
Creates a dropdown button |
.form-check-input |
Styles checkbox or radio controls |
Common Mistakes
- Forgetting to wrap the controls inside .input-group.
- Forgetting .input-group-text when adding text before or after an input.
- Applying .input-group-lg or .input-group-sm directly to the input instead of the Input Group.
- Using too many elements inside a single Input Group, making the layout difficult to understand.
- Forgetting appropriate labels when an Input Group needs a clear field description.
Summary
- .input-group creates the main Bootstrap Input Group.
- .input-group-text adds text, symbols or labels before or after an input.
- Input Groups can contain buttons and dropdowns.
- Checkboxes and radio buttons can also be combined with Input Groups.
- .input-group-sm creates a small Input Group.
- .input-group-lg creates a large Input Group.
- Input Groups are useful for search boxes, currency fields, usernames, URLs and action-based forms.