Bootstrap 5 Button Group

Button Group

Bootstrap 5 allows you to group a series of buttons together in a button group (on a single line):

Please use the class .btn-group class <div> element to create a button group:

Example

<div class="btn-group">
  <button type="button" class="btn btn-primary">Huawei</button>
  <button type="button" class="btn btn-primary">DJI</button>
  <button type="button" class="btn btn-primary">Xiaomi</button>
</div>

Try It Yourself

Tip:Please do not apply button size to each button in the group, but use the class .btn-group-lg Used for large button groups or to .btn-group-sm Used for small button groups:

Example

<div class="btn-group btn-group-lg">
  <button type="button" class="btn btn-primary">Huawei</button>
  <button type="button" class="btn btn-primary">DJI</button>
  <button type="button" class="btn btn-primary">Xiaomi</button>
</div>

Try It Yourself

Vertical Button Groups

Bootstrap 5 also supports vertical button groups:

Please use the class .btn-group-vertical Create a vertical button group:

Example

<div class="btn-group-vertical">
  <button type="button" class="btn btn-primary">Huawei</button>
  <button type="button" class="btn btn-primary">DJI</button>
  <button type="button" class="btn btn-primary">Xiaomi</button>
</div>

Try It Yourself

Side-by-Side Button Groups

By default, button groups are 'inline', and multiple button groups will be displayed side by side when there are multiple button groups:

Example

<div class="btn-group">
  <button type="button" class="btn btn-primary">Huawei</button>
  <button type="button" class="btn btn-primary">DJI</button>
  <button type="button" class="btn btn-primary">Xiaomi</button>
</div>
<div class="btn-group">
  <button type="button" class="btn btn-primary">Geely</button>
  <button type="button" class="btn btn-primary">Great Wall</button>
  <button type="button" class="btn btn-primary">Hongqi</button>
</div>

Try It Yourself

Nested Button Groups and Dropdown Menus

Nested button groups can create dropdown menus (you will learn more about dropdown menus in the following chapters):

Example

<div class="btn-group">
  <button type="button" class="btn btn-primary">Huawei</button>
  <button type="button" class="btn btn-primary">DJI</button>
  <div class="btn-group">
    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Xiaomi</button>
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#">Phone</a>
      <a class="dropdown-item" href="#">Tablet</a>
    </div>
  </div>
</div>

Try It Yourself