TExcelTAD
Home › Bootstrap › BS5 Input Groups

Bootstrap 5 Input Groups

An input group attaches text, icons or buttons directly to the side of a form control, so they look like one piece: a $ before a price, @ before a username, .com after a domain, or a "Search" button joined to a search box.

Text add-ons

Wrap the control in .input-group and put the add-on text in a .input-group-text element before or after it.

html · try it yourself
<!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/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="input-group mb-2">
    <span class="input-group-text" id="at">@</span>
    <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="at">
  </div>
  <div class="input-group mb-2">
    <input type="text" class="form-control" placeholder="your-site" aria-label="Domain">
    <span class="input-group-text">.com</span>
  </div>
  <div class="input-group mb-2">
    <span class="input-group-text">
lt;/span> <input type="number" class="form-control" aria-label="Amount" value="25"> <span class="input-group-text">.00</span> </div> <div class="input-group"> <span class="input-group-text">First and last</span> <input type="text" aria-label="First name" class="form-control"> <input type="text" aria-label="Last name" class="form-control"> </div> </body> </html>

Buttons and dropdowns

Buttons go directly inside the group (no extra wrapper). Dropdowns work too, with Bootstrap's JavaScript loaded.

html · try it yourself
<!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/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3" style="min-height: 240px;">
  <div class="input-group mb-2">
    <input type="search" class="form-control" placeholder="Search lessons…" aria-label="Search" id="q">
    <button class="btn btn-primary" type="button" id="go">🔍 Search</button>
  </div>
  <div class="input-group mb-2">
    <button class="btn btn-outline-secondary" type="button" id="minus">−</button>
    <input type="text" class="form-control text-center" value="1" aria-label="Quantity" id="qty">
    <button class="btn btn-outline-secondary" type="button" id="plus">+</button>
  </div>
  <div class="input-group">
    <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" id="unitBtn">kg</button>
    <ul class="dropdown-menu">
      <li><a class="dropdown-item" href="#">kg</a></li>
      <li><a class="dropdown-item" href="#">lb</a></li>
    </ul>
    <input type="number" class="form-control" aria-label="Weight" value="70">
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  <script>
    const qty = document.getElementById('qty');
    document.getElementById('plus').onclick = () => { qty.value = Number(qty.value) + 1; };
    document.getElementById('minus').onclick = () => { qty.value = Math.max(1, Number(qty.value) - 1); };
    document.getElementById('go').onclick = () => console.log('searching for', document.getElementById('q').value);
    document.querySelectorAll('.dropdown-item').forEach((a) => a.addEventListener('click', (e) => {
      e.preventDefault();
      document.getElementById('unitBtn').textContent = a.textContent;
    }));
  </script>
</body>
</html>

Sizes, checkboxes and selects

Size the whole group with .input-group-lg or .input-group-sm. An add-on can also hold a checkbox or radio (add .mt-0 to the input to remove its top margin), and selects and textareas fit in a group as well.

html · try it yourself
<!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/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="input-group input-group-sm mb-2">
    <span class="input-group-text">Small</span>
    <input type="text" class="form-control" aria-label="Small input">
  </div>
  <div class="input-group input-group-lg mb-2">
    <span class="input-group-text">Large</span>
    <input type="text" class="form-control" aria-label="Large input">
  </div>
  <div class="input-group mb-2">
    <div class="input-group-text">
      <input class="form-check-input mt-0" type="checkbox" aria-label="Enable custom URL">
    </div>
    <input type="text" class="form-control" aria-label="Custom URL" placeholder="Custom URL">
  </div>
  <div class="input-group">
    <label class="input-group-text" for="plan">Plan</label>
    <select class="form-select" id="plan"><option>Free</option><option>Pro</option></select>
  </div>
</body>
</html>

Class reference

Class Purpose
.input-group Wrapper (flex container)
.input-group-text Text, icon, checkbox or radio add-on
.input-group-lg / .input-group-sm Size every element in the group
.flex-nowrap Prevent wrapping onto two lines
.has-validation Keeps corners right when validation feedback follows

Buttons (.btn), .form-control, .form-select and .dropdown-toggle can all be direct children.

Note: Placeholder text and add-ons aren't a replacement for a label. If the field has no visible <label>, give the input an aria-label, as in the examples above.

Tip: For an icon add-on, any emoji or icon font works: <span class="input-group-text">🔒</span> before a password field.

Test yourself

Which class styles the text attached to an input, such as "@"?

  1. .input-addon
  2. .input-group-text
  3. .input-group-addon
  4. .form-text

How do you attach a button to the right of an input?

  1. Wrap it in .input-group-append
  2. Put the .btn directly inside .input-group after the input
  3. Add .btn-attached
  4. Use .input-group-btn

How do you make all elements in an input group small?

  1. .form-control-sm on each
  2. .input-group-sm on the group
  3. .btn-sm on the group
  4. .small on the group