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

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

  1. <div class="input-group flex-nowrap">
  2. <div class="input-group-prepend">
  3. <span class="input-group-text" id="addon-wrapping">@</span>
  4. </div>
  5. <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
  6. </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

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

Checkboxes and radios

Place any checkbox or radio option within an input group’s addon instead of text.

Input group - 图4

  1. <div class="input-group mb-3">
  2. <div class="input-group-prepend">
  3. <div class="input-group-text">
  4. <input type="checkbox" aria-label="Checkbox for following text input">
  5. </div>
  6. </div>
  7. <input type="text" class="form-control" aria-label="Text input with checkbox">
  8. </div>
  9. <div class="input-group">
  10. <div class="input-group-prepend">
  11. <div class="input-group-text">
  12. <input type="radio" aria-label="Radio button for following text input">
  13. </div>
  14. </div>
  15. <input type="text" class="form-control" aria-label="Text input with radio button">
  16. </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

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

Multiple addons

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

Input group - 图6

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

Button addons

Input group - 图7

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

Buttons with dropdowns

Input group - 图8

  1. <div class="input-group mb-3">
  2. <div class="input-group-prepend">
  3. <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</button>
  4. <div class="dropdown-menu">
  5. <a class="dropdown-item" href="#">Action</a>
  6. <a class="dropdown-item" href="#">Another action</a>
  7. <a class="dropdown-item" href="#">Something else here</a>
  8. <div role="separator" class="dropdown-divider"></div>
  9. <a class="dropdown-item" href="#">Separated link</a>
  10. </div>
  11. </div>
  12. <input type="text" class="form-control" aria-label="Text input with dropdown button">
  13. </div>
  14. <div class="input-group">
  15. <input type="text" class="form-control" aria-label="Text input with dropdown button">
  16. <div class="input-group-append">
  17. <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</button>
  18. <div class="dropdown-menu">
  19. <a class="dropdown-item" href="#">Action</a>
  20. <a class="dropdown-item" href="#">Another action</a>
  21. <a class="dropdown-item" href="#">Something else here</a>
  22. <div role="separator" class="dropdown-divider"></div>
  23. <a class="dropdown-item" href="#">Separated link</a>
  24. </div>
  25. </div>
  26. </div>

Segmented buttons

Input group - 图9

  1. <div class="input-group mb-3">
  2. <div class="input-group-prepend">
  3. <button type="button" class="btn btn-outline-secondary">Action</button>
  4. <button type="button" class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  5. <span class="sr-only">Toggle Dropdown</span>
  6. </button>
  7. <div class="dropdown-menu">
  8. <a class="dropdown-item" href="#">Action</a>
  9. <a class="dropdown-item" href="#">Another action</a>
  10. <a class="dropdown-item" href="#">Something else here</a>
  11. <div role="separator" class="dropdown-divider"></div>
  12. <a class="dropdown-item" href="#">Separated link</a>
  13. </div>
  14. </div>
  15. <input type="text" class="form-control" aria-label="Text input with segmented dropdown button">
  16. </div>
  17. <div class="input-group">
  18. <input type="text" class="form-control" aria-label="Text input with segmented dropdown button">
  19. <div class="input-group-append">
  20. <button type="button" class="btn btn-outline-secondary">Action</button>
  21. <button type="button" class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  22. <span class="sr-only">Toggle Dropdown</span>
  23. </button>
  24. <div class="dropdown-menu">
  25. <a class="dropdown-item" href="#">Action</a>
  26. <a class="dropdown-item" href="#">Another action</a>
  27. <a class="dropdown-item" href="#">Something else here</a>
  28. <div role="separator" class="dropdown-divider"></div>
  29. <a class="dropdown-item" href="#">Separated link</a>
  30. </div>
  31. </div>
  32. </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

<div class="input-group mb-3">
  <div class="input-group-prepend">
    <label class="input-group-text" for="inputGroupSelect01">Options</label>
  </div>
  <select class="custom-select" id="inputGroupSelect01">
    <option selected>Choose...</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
</div>

<div class="input-group mb-3">
  <select class="custom-select" id="inputGroupSelect02">
    <option selected>Choose...</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
  <div class="input-group-append">
    <label class="input-group-text" for="inputGroupSelect02">Options</label>
  </div>
</div>

<div class="input-group mb-3">
  <div class="input-group-prepend">
    <button class="btn btn-outline-secondary" type="button">Button</button>
  </div>
  <select class="custom-select" id="inputGroupSelect03" aria-label="Example select with button addon">
    <option selected>Choose...</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
</div>

<div class="input-group">
  <select class="custom-select" id="inputGroupSelect04" aria-label="Example select with button addon">
    <option selected>Choose...</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
  <div class="input-group-append">
    <button class="btn btn-outline-secondary" type="button">Button</button>
  </div>
</div>

Custom file input

Input group - 图11

<div class="input-group mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text" id="inputGroupFileAddon01">Upload</span>
  </div>
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile01" aria-describedby="inputGroupFileAddon01">
    <label class="custom-file-label" for="inputGroupFile01">Choose file</label>
  </div>
</div>

<div class="input-group mb-3">
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile02">
    <label class="custom-file-label" for="inputGroupFile02" aria-describedby="inputGroupFileAddon02">Choose file</label>
  </div>
  <div class="input-group-append">
    <span class="input-group-text" id="inputGroupFileAddon02">Upload</span>
  </div>
</div>

<div class="input-group mb-3">
  <div class="input-group-prepend">
    <button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon03">Button</button>
  </div>
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile03" aria-describedby="inputGroupFileAddon03">
    <label class="custom-file-label" for="inputGroupFile03">Choose file</label>
  </div>
</div>

<div class="input-group">
  <div class="custom-file">
    <input type="file" class="custom-file-input" id="inputGroupFile04" aria-describedby="inputGroupFileAddon04">
    <label class="custom-file-label" for="inputGroupFile04">Choose file</label>
  </div>
  <div class="input-group-append">
    <button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon04">Button</button>
  </div>
</div>

Accessibility

Screen readers will have trouble with your forms if you don’t include a label for every input. For these input groups, ensure that any additional label or functionality is conveyed to assistive technologies.

The exact technique to be used (<label> elements hidden using the .sr-only class, or use of the aria-label and aria-labelledby attributes, possibly in combination with aria-describedby) and what additional information will need to be conveyed will vary depending on the exact type of interface widget you’re implementing. The examples in this section provide a few suggested, case-specific approaches.