← Back to Bootstrap Course | Chapter 5: Components — Buttons & Forms | Lesson 3 of 7

Button groups

Button groups join related buttons into one connected bar.

In this page:

  1. Button groups
Syntax
markup
<div class="btn-group" role="group" aria-label="label">
  <button class="btn btn-primary">one</button>
  <button class="btn btn-primary">two</button>
</div>

Button groups

Wrap buttons in .btn-group with role="group" and an aria-label. Use .btn-group-vertical to stack them and .btn-toolbar to combine several groups. Radio and checkbox toggles with .btn-check render as button groups too.

Note: Always add role="group" and an aria-label for accessibility.

Example: Button groups

markup
<!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/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="btn-group mb-3" role="group" aria-label="Text alignment">
    <button type="button" class="btn btn-outline-primary">Left</button>
    <button type="button" class="btn btn-outline-primary active">Middle</button>
    <button type="button" class="btn btn-outline-primary">Right</button>
  </div>
  <div class="btn-group-vertical d-block" role="group" aria-label="Vertical group" style="width:8rem">
    <button type="button" class="btn btn-secondary">Top</button>
    <button type="button" class="btn btn-secondary">Bottom</button>
  </div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Forgetting role and aria-label
  2. Nesting groups incorrectly
  3. Using groups for unrelated buttons
Chapter Summary
  • .btn-group joins buttons
  • role="group" and aria-label
  • btn-group-vertical stacks
  • btn-toolbar combines groups
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.