← Back to Bootstrap Course | Chapter 5: Components — Buttons & Forms | Lesson 7 of 7

Input groups

Input groups attach text, icons or buttons to the sides of an input.

In this page:

  1. Input groups
Syntax
markup
<div class="input-group">
  <span class="input-group-text">@</span>
  <input type="text" class="form-control">
</div>

Input groups

Wrap an input in .input-group and add .input-group-text or button elements before or after it. Groups can hold several inputs and support size classes like .input-group-lg. Keep a label associated with the input for accessibility.

Note: Put labels outside the input group, not inside it.

Example: Input groups

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <label for="user" class="form-label">Username</label>
  <div class="input-group mb-3"><span class="input-group-text">@</span><input id="user" class="form-control" placeholder="username"></div>
  <div class="input-group"><input class="form-control" placeholder="Search" aria-label="Search"><button class="btn btn-outline-secondary">Go</button></div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting the input-group wrapper
  2. Placing text outside the group
  3. Missing accessible labels
Chapter Summary
  • .input-group wraps controls
  • input-group-text adds addons
  • Buttons can be attached
  • Size classes apply to the group
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.