View on GitHub

Button group

Group a series of buttons together on a single line or stack them in a vertical column.

Basic example

Wrap a series of buttons with .btn in .btn-group.

Button group - 图1

html

  1. <div class="btn-group" role="group" aria-label="Basic example">
  2. <button type="button" class="btn btn-primary">Left</button>
  3. <button type="button" class="btn btn-primary">Middle</button>
  4. <button type="button" class="btn btn-primary">Right</button>
  5. </div>
Ensure correct role and provide a label

In order for assistive technologies (such as screen readers) to convey that a series of buttons is grouped, an appropriate role attribute needs to be provided. For button groups, this would be role="group", while toolbars should have a role="toolbar".

In addition, groups and toolbars should be given an explicit label, as most assistive technologies will otherwise not announce them, despite the presence of the correct role attribute. In the examples provided here, we use aria-label, but alternatives such as aria-labelledby can also be used.

These classes can also be added to groups of links, as an alternative to the .nav navigation components.

Button group - 图2

html

  1. <div class="btn-group">
  2. <a href="#" class="btn btn-primary active" aria-current="page">Active link</a>
  3. <a href="#" class="btn btn-primary">Link</a>
  4. <a href="#" class="btn btn-primary">Link</a>
  5. </div>

Mixed styles

Button group - 图3

html

  1. <div class="btn-group" role="group" aria-label="Basic mixed styles example">
  2. <button type="button" class="btn btn-danger">Left</button>
  3. <button type="button" class="btn btn-warning">Middle</button>
  4. <button type="button" class="btn btn-success">Right</button>
  5. </div>

Outlined styles

Button group - 图4

html

  1. <div class="btn-group" role="group" aria-label="Basic outlined example">
  2. <button type="button" class="btn btn-outline-primary">Left</button>
  3. <button type="button" class="btn btn-outline-primary">Middle</button>
  4. <button type="button" class="btn btn-outline-primary">Right</button>
  5. </div>

Checkbox and radio button groups

Combine button-like checkbox and radio toggle buttons into a seamless looking button group.

Button group - 图5

html

  1. <div class="btn-group" role="group" aria-label="Basic checkbox toggle button group">
  2. <input type="checkbox" class="btn-check" id="btncheck1" autocomplete="off">
  3. <label class="btn btn-outline-primary" for="btncheck1">Checkbox 1</label>
  4. <input type="checkbox" class="btn-check" id="btncheck2" autocomplete="off">
  5. <label class="btn btn-outline-primary" for="btncheck2">Checkbox 2</label>
  6. <input type="checkbox" class="btn-check" id="btncheck3" autocomplete="off">
  7. <label class="btn btn-outline-primary" for="btncheck3">Checkbox 3</label>
  8. </div>

Button group - 图6

html

  1. <div class="btn-group" role="group" aria-label="Basic radio toggle button group">
  2. <input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" checked>
  3. <label class="btn btn-outline-primary" for="btnradio1">Radio 1</label>
  4. <input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off">
  5. <label class="btn btn-outline-primary" for="btnradio2">Radio 2</label>
  6. <input type="radio" class="btn-check" name="btnradio" id="btnradio3" autocomplete="off">
  7. <label class="btn btn-outline-primary" for="btnradio3">Radio 3</label>
  8. </div>

Button toolbar

Combine sets of button groups into button toolbars for more complex components. Use utility classes as needed to space out groups, buttons, and more.

Button group - 图7

html

  1. <div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
  2. <div class="btn-group me-2" role="group" aria-label="First group">
  3. <button type="button" class="btn btn-primary">1</button>
  4. <button type="button" class="btn btn-primary">2</button>
  5. <button type="button" class="btn btn-primary">3</button>
  6. <button type="button" class="btn btn-primary">4</button>
  7. </div>
  8. <div class="btn-group me-2" role="group" aria-label="Second group">
  9. <button type="button" class="btn btn-secondary">5</button>
  10. <button type="button" class="btn btn-secondary">6</button>
  11. <button type="button" class="btn btn-secondary">7</button>
  12. </div>
  13. <div class="btn-group" role="group" aria-label="Third group">
  14. <button type="button" class="btn btn-info">8</button>
  15. </div>
  16. </div>

Feel free to mix input groups with button groups in your toolbars. Similar to the example above, you’ll likely need some utilities though to space things properly.

Button group - 图8

html

  1. <div class="btn-toolbar mb-3" role="toolbar" aria-label="Toolbar with button groups">
  2. <div class="btn-group me-2" role="group" aria-label="First group">
  3. <button type="button" class="btn btn-outline-secondary">1</button>
  4. <button type="button" class="btn btn-outline-secondary">2</button>
  5. <button type="button" class="btn btn-outline-secondary">3</button>
  6. <button type="button" class="btn btn-outline-secondary">4</button>
  7. </div>
  8. <div class="input-group">
  9. <div class="input-group-text" id="btnGroupAddon">@</div>
  10. <input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon">
  11. </div>
  12. </div>
  13. <div class="btn-toolbar justify-content-between" role="toolbar" aria-label="Toolbar with button groups">
  14. <div class="btn-group" role="group" aria-label="First group">
  15. <button type="button" class="btn btn-outline-secondary">1</button>
  16. <button type="button" class="btn btn-outline-secondary">2</button>
  17. <button type="button" class="btn btn-outline-secondary">3</button>
  18. <button type="button" class="btn btn-outline-secondary">4</button>
  19. </div>
  20. <div class="input-group">
  21. <div class="input-group-text" id="btnGroupAddon2">@</div>
  22. <input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon2">
  23. </div>
  24. </div>

Sizing

Instead of applying button sizing classes to every button in a group, just add .btn-group-* to each .btn-group, including each one when nesting multiple groups.

Button group - 图9

html

  1. <div class="btn-group btn-group-lg" role="group" aria-label="Large button group">
  2. <button type="button" class="btn btn-outline-dark">Left</button>
  3. <button type="button" class="btn btn-outline-dark">Middle</button>
  4. <button type="button" class="btn btn-outline-dark">Right</button>
  5. </div>
  6. <br>
  7. <div class="btn-group" role="group" aria-label="Default button group">
  8. <button type="button" class="btn btn-outline-dark">Left</button>
  9. <button type="button" class="btn btn-outline-dark">Middle</button>
  10. <button type="button" class="btn btn-outline-dark">Right</button>
  11. </div>
  12. <br>
  13. <div class="btn-group btn-group-sm" role="group" aria-label="Small button group">
  14. <button type="button" class="btn btn-outline-dark">Left</button>
  15. <button type="button" class="btn btn-outline-dark">Middle</button>
  16. <button type="button" class="btn btn-outline-dark">Right</button>
  17. </div>

Nesting

Place a .btn-group within another .btn-group when you want dropdown menus mixed with a series of buttons.

Button group - 图10

html

  1. <div class="btn-group" role="group" aria-label="Button group with nested dropdown">
  2. <button type="button" class="btn btn-primary">1</button>
  3. <button type="button" class="btn btn-primary">2</button>
  4. <div class="btn-group" role="group">
  5. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  6. Dropdown
  7. </button>
  8. <ul class="dropdown-menu">
  9. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  10. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  11. </ul>
  12. </div>
  13. </div>

Vertical variation

Make a set of buttons appear vertically stacked rather than horizontally. Split button dropdowns are not supported here.

Button group - 图11

html

  1. <div class="btn-group-vertical" role="group" aria-label="Vertical button group">
  2. <button type="button" class="btn btn-dark">Button</button>
  3. <button type="button" class="btn btn-dark">Button</button>
  4. <button type="button" class="btn btn-dark">Button</button>
  5. <button type="button" class="btn btn-dark">Button</button>
  6. <button type="button" class="btn btn-dark">Button</button>
  7. <button type="button" class="btn btn-dark">Button</button>
  8. </div>

Button group - 图12

html

  1. <div class="btn-group-vertical" role="group" aria-label="Vertical button group">
  2. <button type="button" class="btn btn-primary">Button</button>
  3. <button type="button" class="btn btn-primary">Button</button>
  4. <div class="btn-group" role="group">
  5. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  6. Dropdown
  7. </button>
  8. <ul class="dropdown-menu">
  9. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  10. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  11. </ul>
  12. </div>
  13. <button type="button" class="btn btn-primary">Button</button>
  14. <button type="button" class="btn btn-primary">Button</button>
  15. <div class="btn-group" role="group">
  16. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  17. Dropdown
  18. </button>
  19. <ul class="dropdown-menu">
  20. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  21. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  22. </ul>
  23. </div>
  24. <div class="btn-group" role="group">
  25. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  26. Dropdown
  27. </button>
  28. <ul class="dropdown-menu">
  29. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  30. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  31. </ul>
  32. </div>
  33. <div class="btn-group" role="group">
  34. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  35. Dropdown
  36. </button>
  37. <ul class="dropdown-menu">
  38. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  39. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  40. </ul>
  41. </div>
  42. </div>

Button group - 图13

html

  1. <div class="btn-group-vertical" role="group" aria-label="Vertical radio toggle button group">
  2. <input type="radio" class="btn-check" name="vbtn-radio" id="vbtn-radio1" autocomplete="off" checked>
  3. <label class="btn btn-outline-danger" for="vbtn-radio1">Radio 1</label>
  4. <input type="radio" class="btn-check" name="vbtn-radio" id="vbtn-radio2" autocomplete="off">
  5. <label class="btn btn-outline-danger" for="vbtn-radio2">Radio 2</label>
  6. <input type="radio" class="btn-check" name="vbtn-radio" id="vbtn-radio3" autocomplete="off">
  7. <label class="btn btn-outline-danger" for="vbtn-radio3">Radio 3</label>
  8. </div>