Input groups help you add extra things like buttons or text next to input boxes. This makes forms easier to use and understand.
Input groups in Bootsrap
<div class="input-group"> <span class="input-group-text">Text or symbol</span> <input type="text" class="form-control" placeholder="Your input"> </div>
input-group as the container for grouping inputs and addons.input-group-text for static text or symbols next to inputs.<div class="input-group"> <span class="input-group-text">@</span> <input type="text" class="form-control" placeholder="Username"> </div>
<div class="input-group"> <input type="text" class="form-control" placeholder="Amount"> <span class="input-group-text">$</span> </div>
<div class="input-group"> <button class="btn btn-primary" type="button">Go</button> <input type="text" class="form-control" placeholder="Search"> </div>
This example shows three input groups: one with '@' before the username input, one with '$' after the amount input, and one with a 'Go' button before the search input. It uses Bootstrap 5.3 for styling and accessibility features like labels and aria attributes.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Input Groups Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-5"> <h1>Input Groups Demo</h1> <form> <div class="mb-3"> <label for="username" class="form-label">Username</label> <div class="input-group"> <span class="input-group-text" id="basic-addon1">@</span> <input type="text" class="form-control" id="username" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1"> </div> </div> <div class="mb-3"> <label for="amount" class="form-label">Amount</label> <div class="input-group"> <input type="text" class="form-control" id="amount" placeholder="Amount" aria-label="Amount"> <span class="input-group-text">$</span> </div> </div> <div class="mb-3"> <label for="search" class="form-label">Search</label> <div class="input-group"> <button class="btn btn-primary" type="button">Go</button> <input type="text" class="form-control" id="search" placeholder="Search" aria-label="Search"> </div> </div> </form> </main> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Always use aria-label or aria-describedby for better accessibility.
Input groups work well with buttons, text, or icons to improve user experience.
Use Bootstrap's spacing classes like mb-3 to add space between form groups.
Input groups let you add text, symbols, or buttons next to inputs.
They improve form clarity and user interaction.
Bootstrap makes it easy to create input groups with simple classes.
Practice
Solution
Step 1: Understand input groups concept
Input groups in Bootstrap are used to add extra elements like text or buttons next to input fields to improve clarity and interaction.Step 2: Identify the correct purpose
Options A, C, and D describe other Bootstrap features unrelated to input groups.Final Answer:
To add text, symbols, or buttons next to input fields -> Option AQuick Check:
Input groups add elements next to inputs = B [OK]
- Confusing input groups with dropdown menus
- Thinking input groups style tables
- Assuming input groups add animations
Solution
Step 1: Recall Bootstrap input group structure
The container for input groups uses the classinput-groupto wrap inputs and addons.Step 2: Differentiate from other classes
form-controlstyles inputs,btn-groupgroups buttons, andinput-containeris not a Bootstrap class.Final Answer:
input-group -> Option BQuick Check:
Container class for input groups = input-group [OK]
- Using form-control as container instead of input-group
- Confusing btn-group with input-group
- Using non-existent class input-container
<div class="input-group"> <span class="input-group-text">@</span> <input type="text" class="form-control" placeholder="Username" /> </div>
Solution
Step 1: Analyze the input group structure
Theinput-group-textinside theinput-groupadds a styled box with '@' before the input field.Step 2: Understand rendering result
The '@' appears inside a gray box on the left side of the input box, not as a button or placeholder.Final Answer:
An input box with '@' symbol on the left inside a gray box -> Option CQuick Check:
input-group-text adds symbol box next to input = A [OK]
- Thinking input-group-text creates a button
- Confusing placeholder with input-group-text content
- Ignoring the gray box styling around '@'
<div class="input-group">
<input type="text" class="form-control" placeholder="Email" />
<span class="input-group-btn">
<button class="btn btn-primary" type="button">Send</button>
</span>
</div>Solution
Step 1: Check Bootstrap input group button usage
Bootstrap 5 removedinput-group-btn. Buttons inside input groups should be direct children with classbtn.Step 2: Verify other options
Buttons are allowed inside input groups, input can be before or after button, and placeholder is valid on inputs.Final Answer:
The class 'input-group-btn' is deprecated and should be replaced -> Option AQuick Check:
input-group-btn deprecated in Bootstrap 5 = D [OK]
- Keeping input-group-btn class from older Bootstrap versions
- Thinking buttons can't be inside input groups
- Believing placeholder is invalid in input groups
Solution
Step 1: Understand input group with dropdown button
The dropdown button must be a button withdropdown-toggleclass and properdata-bs-toggleattribute inside the input group after the input.Step 2: Check structure correctness
Options correctly places the input first, then the dropdown button with toggle attributes, followed by the dropdown menu list.Final Answer:
This structure correctly creates an input group with a dropdown button on the right -> Option DQuick Check:
Dropdown button after input with toggle attribute = A [OK]
- Placing dropdown menu before button
- Using span instead of button for dropdown toggle
- Putting button before input in input group
Ready to prove it?
Pass the test and this pattern moves unknown
