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>

Button groups require an appropriate role attribute and explicit label to ensure assistive technologies like screen readers identify buttons as grouped and announce them. Use role="group" for button groups or role="toolbar" for button toolbars. Then use aria-label or aria-labelledby to label them.

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-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>
  6. <br>
  7. <div class="btn-group" role="group" aria-label="Default button group">
  8. <button type="button" class="btn btn-outline-primary">Left</button>
  9. <button type="button" class="btn btn-outline-primary">Middle</button>
  10. <button type="button" class="btn btn-outline-primary">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-primary">Left</button>
  15. <button type="button" class="btn btn-outline-primary">Middle</button>
  16. <button type="button" class="btn btn-outline-primary">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-primary">Button</button>
  3. <button type="button" class="btn btn-primary">Button</button>
  4. <button type="button" class="btn btn-primary">Button</button>
  5. <button type="button" class="btn btn-primary">Button</button>
  6. </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. <div class="btn-group dropstart" role="group">
  14. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  15. Dropdown
  16. </button>
  17. <ul class="dropdown-menu">
  18. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  19. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  20. </ul>
  21. </div>
  22. <div class="btn-group dropend" role="group">
  23. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  24. Dropdown
  25. </button>
  26. <ul class="dropdown-menu">
  27. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  28. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  29. </ul>
  30. </div>
  31. <div class="btn-group dropup" role="group">
  32. <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
  33. Dropdown
  34. </button>
  35. <ul class="dropdown-menu">
  36. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  37. <li><a class="dropdown-item" href="#">Dropdown link</a></li>
  38. </ul>
  39. </div>
  40. </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>