Input group

Easily extend form controls by adding text, buttons, or button groups on either side of textual inputs, custom selects, and custom file inputs.

Basic example

Place one add-on or button on either side of an input. You may also place one on both sides of an input. Remember to place <label>s outside the input group.

Input group - 图1

html

  1. <div class="input-group mb-3">
  2. <span class="input-group-text" id="basic-addon1">@</span>
  3. <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
  4. </div>
  5. <div class="input-group mb-3">
  6. <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="basic-addon2">
  7. <span class="input-group-text" id="basic-addon2">@example.com</span>
  8. </div>
  9. <div class="mb-3">
  10. <label for="basic-url" class="form-label">Your vanity URL</label>
  11. <div class="input-group">
  12. <span class="input-group-text" id="basic-addon3">https://example.com/users/</span>
  13. <input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3 basic-addon4">
  14. </div>
  15. <div class="form-text" id="basic-addon4">Example help text goes outside the input group.</div>
  16. </div>
  17. <div class="input-group mb-3">
  18. <span class="input-group-text">$</span>
  19. <input type="text" class="form-control" aria-label="Amount (to the nearest dollar)">
  20. <span class="input-group-text">.00</span>
  21. </div>
  22. <div class="input-group mb-3">
  23. <input type="text" class="form-control" placeholder="Username" aria-label="Username">
  24. <span class="input-group-text">@</span>
  25. <input type="text" class="form-control" placeholder="Server" aria-label="Server">
  26. </div>
  27. <div class="input-group">
  28. <span class="input-group-text">With textarea</span>
  29. <textarea class="form-control" aria-label="With textarea"></textarea>
  30. </div>

Wrapping

Input groups wrap by default via flex-wrap: wrap in order to accommodate custom form field validation within an input group. You may disable this with .flex-nowrap.

Input group - 图2

html

  1. <div class="input-group flex-nowrap">
  2. <span class="input-group-text" id="addon-wrapping">@</span>
  3. <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
  4. </div>

Sizing

Add the relative form sizing classes to the .input-group itself and contents within will automatically resize—no need for repeating the form control size classes on each element.

Sizing on the individual input group elements isn’t supported.

Input group - 图3

html

  1. <div class="input-group input-group-sm mb-3">
  2. <span class="input-group-text" id="inputGroup-sizing-sm">Small</span>
  3. <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
  4. </div>
  5. <div class="input-group mb-3">
  6. <span class="input-group-text" id="inputGroup-sizing-default">Default</span>
  7. <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
  8. </div>
  9. <div class="input-group input-group-lg">
  10. <span class="input-group-text" id="inputGroup-sizing-lg">Large</span>
  11. <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-lg">
  12. </div>

Checkboxes and radios

Place any checkbox or radio option within an input group’s addon instead of text. We recommend adding .mt-0 to the .form-check-input when there’s no visible text next to the input.

Input group - 图4

html

  1. <div class="input-group mb-3">
  2. <div class="input-group-text">
  3. <input class="form-check-input mt-0" type="checkbox" value="" aria-label="Checkbox for following text input">
  4. </div>
  5. <input type="text" class="form-control" aria-label="Text input with checkbox">
  6. </div>
  7. <div class="input-group">
  8. <div class="input-group-text">
  9. <input class="form-check-input mt-0" type="radio" value="" aria-label="Radio button for following text input">
  10. </div>
  11. <input type="text" class="form-control" aria-label="Text input with radio button">
  12. </div>

Multiple inputs

While multiple <input>s are supported visually, validation styles are only available for input groups with a single <input>.

Input group - 图5

html

  1. <div class="input-group">
  2. <span class="input-group-text">First and last name</span>
  3. <input type="text" aria-label="First name" class="form-control">
  4. <input type="text" aria-label="Last name" class="form-control">
  5. </div>

Multiple addons

Multiple add-ons are supported and can be mixed with checkbox and radio input versions.

Input group - 图6

html

  1. <div class="input-group mb-3">
  2. <span class="input-group-text">$</span>
  3. <span class="input-group-text">0.00</span>
  4. <input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
  5. </div>
  6. <div class="input-group">
  7. <input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
  8. <span class="input-group-text">$</span>
  9. <span class="input-group-text">0.00</span>
  10. </div>

Button addons

Input group - 图7

html

  1. <div class="input-group mb-3">
  2. <button class="btn btn-outline-secondary" type="button" id="button-addon1">Button</button>
  3. <input type="text" class="form-control" placeholder="" aria-label="Example text with button addon" aria-describedby="button-addon1">
  4. </div>
  5. <div class="input-group mb-3">
  6. <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="button-addon2">
  7. <button class="btn btn-outline-secondary" type="button" id="button-addon2">Button</button>
  8. </div>
  9. <div class="input-group mb-3">
  10. <button class="btn btn-outline-secondary" type="button">Button</button>
  11. <button class="btn btn-outline-secondary" type="button">Button</button>
  12. <input type="text" class="form-control" placeholder="" aria-label="Example text with two button addons">
  13. </div>
  14. <div class="input-group">
  15. <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username with two button addons">
  16. <button class="btn btn-outline-secondary" type="button">Button</button>
  17. <button class="btn btn-outline-secondary" type="button">Button</button>
  18. </div>

Buttons with dropdowns

Input group - 图8

html

  1. <div class="input-group mb-3">
  2. <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>
  3. <ul class="dropdown-menu">
  4. <li><a class="dropdown-item" href="#">Action</a></li>
  5. <li><a class="dropdown-item" href="#">Another action</a></li>
  6. <li><a class="dropdown-item" href="#">Something else here</a></li>
  7. <li><hr class="dropdown-divider"></li>
  8. <li><a class="dropdown-item" href="#">Separated link</a></li>
  9. </ul>
  10. <input type="text" class="form-control" aria-label="Text input with dropdown button">
  11. </div>
  12. <div class="input-group mb-3">
  13. <input type="text" class="form-control" aria-label="Text input with dropdown button">
  14. <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>
  15. <ul class="dropdown-menu dropdown-menu-end">
  16. <li><a class="dropdown-item" href="#">Action</a></li>
  17. <li><a class="dropdown-item" href="#">Another action</a></li>
  18. <li><a class="dropdown-item" href="#">Something else here</a></li>
  19. <li><hr class="dropdown-divider"></li>
  20. <li><a class="dropdown-item" href="#">Separated link</a></li>
  21. </ul>
  22. </div>
  23. <div class="input-group">
  24. <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>
  25. <ul class="dropdown-menu">
  26. <li><a class="dropdown-item" href="#">Action before</a></li>
  27. <li><a class="dropdown-item" href="#">Another action before</a></li>
  28. <li><a class="dropdown-item" href="#">Something else here</a></li>
  29. <li><hr class="dropdown-divider"></li>
  30. <li><a class="dropdown-item" href="#">Separated link</a></li>
  31. </ul>
  32. <input type="text" class="form-control" aria-label="Text input with 2 dropdown buttons">
  33. <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</button>
  34. <ul class="dropdown-menu dropdown-menu-end">
  35. <li><a class="dropdown-item" href="#">Action</a></li>
  36. <li><a class="dropdown-item" href="#">Another action</a></li>
  37. <li><a class="dropdown-item" href="#">Something else here</a></li>
  38. <li><hr class="dropdown-divider"></li>
  39. <li><a class="dropdown-item" href="#">Separated link</a></li>
  40. </ul>
  41. </div>

Segmented buttons

Input group - 图9

html

  1. <div class="input-group mb-3">
  2. <button type="button" class="btn btn-outline-secondary">Action</button>
  3. <button type="button" class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  4. <span class="visually-hidden">Toggle Dropdown</span>
  5. </button>
  6. <ul class="dropdown-menu">
  7. <li><a class="dropdown-item" href="#">Action</a></li>
  8. <li><a class="dropdown-item" href="#">Another action</a></li>
  9. <li><a class="dropdown-item" href="#">Something else here</a></li>
  10. <li><hr class="dropdown-divider"></li>
  11. <li><a class="dropdown-item" href="#">Separated link</a></li>
  12. </ul>
  13. <input type="text" class="form-control" aria-label="Text input with segmented dropdown button">
  14. </div>
  15. <div class="input-group">
  16. <input type="text" class="form-control" aria-label="Text input with segmented dropdown button">
  17. <button type="button" class="btn btn-outline-secondary">Action</button>
  18. <button type="button" class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
  19. <span class="visually-hidden">Toggle Dropdown</span>
  20. </button>
  21. <ul class="dropdown-menu dropdown-menu-end">
  22. <li><a class="dropdown-item" href="#">Action</a></li>
  23. <li><a class="dropdown-item" href="#">Another action</a></li>
  24. <li><a class="dropdown-item" href="#">Something else here</a></li>
  25. <li><hr class="dropdown-divider"></li>
  26. <li><a class="dropdown-item" href="#">Separated link</a></li>
  27. </ul>
  28. </div>

Custom forms

Input groups include support for custom selects and custom file inputs. Browser default versions of these are not supported.

Custom select

Input group - 图10

html

  1. <div class="input-group mb-3">
  2. <label class="input-group-text" for="inputGroupSelect01">Options</label>
  3. <select class="form-select" id="inputGroupSelect01">
  4. <option selected>Choose...</option>
  5. <option value="1">One</option>
  6. <option value="2">Two</option>
  7. <option value="3">Three</option>
  8. </select>
  9. </div>
  10. <div class="input-group mb-3">
  11. <select class="form-select" id="inputGroupSelect02">
  12. <option selected>Choose...</option>
  13. <option value="1">One</option>
  14. <option value="2">Two</option>
  15. <option value="3">Three</option>
  16. </select>
  17. <label class="input-group-text" for="inputGroupSelect02">Options</label>
  18. </div>
  19. <div class="input-group mb-3">
  20. <button class="btn btn-outline-secondary" type="button">Button</button>
  21. <select class="form-select" id="inputGroupSelect03" aria-label="Example select with button addon">
  22. <option selected>Choose...</option>
  23. <option value="1">One</option>
  24. <option value="2">Two</option>
  25. <option value="3">Three</option>
  26. </select>
  27. </div>
  28. <div class="input-group">
  29. <select class="form-select" id="inputGroupSelect04" aria-label="Example select with button addon">
  30. <option selected>Choose...</option>
  31. <option value="1">One</option>
  32. <option value="2">Two</option>
  33. <option value="3">Three</option>
  34. </select>
  35. <button class="btn btn-outline-secondary" type="button">Button</button>
  36. </div>

Custom file input

Input group - 图11

html

  1. <div class="input-group mb-3">
  2. <label class="input-group-text" for="inputGroupFile01">Upload</label>
  3. <input type="file" class="form-control" id="inputGroupFile01">
  4. </div>
  5. <div class="input-group mb-3">
  6. <input type="file" class="form-control" id="inputGroupFile02">
  7. <label class="input-group-text" for="inputGroupFile02">Upload</label>
  8. </div>
  9. <div class="input-group mb-3">
  10. <button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon03">Button</button>
  11. <input type="file" class="form-control" id="inputGroupFile03" aria-describedby="inputGroupFileAddon03" aria-label="Upload">
  12. </div>
  13. <div class="input-group">
  14. <input type="file" class="form-control" id="inputGroupFile04" aria-describedby="inputGroupFileAddon04" aria-label="Upload">
  15. <button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon04">Button</button>
  16. </div>

CSS

Sass variables

scss/_variables.scss

  1. $input-group-addon-padding-y: $input-padding-y;
  2. $input-group-addon-padding-x: $input-padding-x;
  3. $input-group-addon-font-weight: $input-font-weight;
  4. $input-group-addon-color: $input-color;
  5. $input-group-addon-bg: var(--#{$prefix}tertiary-bg);
  6. $input-group-addon-border-color: $input-border-color;