TExcelTAD
Home › Bootstrap › BS5 Button Groups

Bootstrap 5 Button Groups

A button group joins several buttons into a single unit: the borders between them merge and only the outer corners stay rounded. It's perfect for toolbars, segmented controls and "pick one" options.

A basic group

Wrap the buttons in a .btn-group. Give the group role="group" and an aria-label so screen readers know what it is.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="btn-group mb-3" role="group" aria-label="Text alignment">
    <button type="button" class="btn btn-primary">Left</button>
    <button type="button" class="btn btn-primary">Center</button>
    <button type="button" class="btn btn-primary">Right</button>
  </div>
  <br>
  <div class="btn-group" role="group" aria-label="Pages">
    <a href="#" class="btn btn-outline-secondary active" aria-current="page">Day</a>
    <a href="#" class="btn btn-outline-secondary">Week</a>
    <a href="#" class="btn btn-outline-secondary">Month</a>
  </div>
</body>
</html>

Sizes and vertical groups

Size every button at once with .btn-group-lg or .btn-group-sm on the group. .btn-group-vertical stacks the buttons instead.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="d-flex gap-4 align-items-start">
    <div>
      <div class="btn-group btn-group-lg mb-2" role="group" aria-label="Large"><button class="btn btn-dark">A</button><button class="btn btn-dark">B</button></div><br>
      <div class="btn-group mb-2" role="group" aria-label="Default"><button class="btn btn-dark">A</button><button class="btn btn-dark">B</button></div><br>
      <div class="btn-group btn-group-sm" role="group" aria-label="Small"><button class="btn btn-dark">A</button><button class="btn btn-dark">B</button></div>
    </div>
    <div class="btn-group-vertical" role="group" aria-label="Vertical">
      <button class="btn btn-outline-primary">Top</button>
      <button class="btn btn-outline-primary">Middle</button>
      <button class="btn btn-outline-primary">Bottom</button>
    </div>
  </div>
</body>
</html>

Checkbox and radio toggle groups

Combine button groups with hidden checkbox or radio inputs to build segmented controls. The input gets .btn-check (which visually hides it), and its <label> gets the button classes. This needs no JavaScript — the browser's own input state drives the :checked style.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <p class="mb-1">Size (radio — pick one):</p>
  <div class="btn-group mb-3" role="group" aria-label="Size">
    <input type="radio" class="btn-check" name="size" id="s" value="S" autocomplete="off">
    <label class="btn btn-outline-primary" for="s">S</label>
    <input type="radio" class="btn-check" name="size" id="m" value="M" autocomplete="off" checked>
    <label class="btn btn-outline-primary" for="m">M</label>
    <input type="radio" class="btn-check" name="size" id="l" value="L" autocomplete="off">
    <label class="btn btn-outline-primary" for="l">L</label>
  </div>
  <p class="mb-1">Extras (checkbox — pick any):</p>
  <div class="btn-group" role="group" aria-label="Extras">
    <input type="checkbox" class="btn-check" id="cheese" autocomplete="off">
    <label class="btn btn-outline-success" for="cheese">🧀 Cheese</label>
    <input type="checkbox" class="btn-check" id="olives" autocomplete="off">
    <label class="btn btn-outline-success" for="olives">🫒 Olives</label>
  </div>
  <script>
    document.addEventListener('change', (e) => console.log(e.target.id, '→', e.target.checked));
  </script>
</body>
</html>

Toolbars and nested dropdowns

A .btn-toolbar holds several groups in a row. A group can also contain a dropdown: nest a .btn-group with a .dropdown-toggle button inside (needs the JavaScript bundle).

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
  <div class="btn-toolbar gap-2" role="toolbar" aria-label="Editor toolbar">
    <div class="btn-group" role="group" aria-label="Format">
      <button class="btn btn-light border fw-bold">B</button>
      <button class="btn btn-light border fst-italic">I</button>
      <button class="btn btn-light border text-decoration-underline">U</button>
    </div>
    <div class="btn-group" role="group" aria-label="Insert">
      <button class="btn btn-light border">🔗</button>
      <div class="btn-group" role="group">
        <button class="btn btn-light border dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">More</button>
        <ul class="dropdown-menu">
          <li><a class="dropdown-item" href="#">Table</a></li>
          <li><a class="dropdown-item" href="#">Image</a></li>
        </ul>
      </div>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Class reference

Class Purpose
.btn-group Horizontal group of buttons
.btn-group-vertical Vertical group
.btn-group-lg / .btn-group-sm Size all buttons in the group
.btn-toolbar Row of several button groups
.btn-check Visually hidden checkbox/radio that drives a button-styled label

Tip: Add gap-2 (or margin utilities) on a .btn-toolbar to space the groups; the toolbar is a flex container but has no gap by default.

Test yourself

Which class stacks grouped buttons vertically?

  1. .btn-group-column
  2. .btn-group-vertical
  3. .flex-column
  4. .btn-stack

In a radio toggle group, which element gets the .btn classes?

  1. The input
  2. The label
  3. The group div
  4. A wrapping span

How do you make every button in a group small?

  1. Add .btn-sm to the group
  2. Add .btn-group-sm to the group
  3. Add .small to the group
  4. It's not possible