Bootstrap 5 Button Group
Bootstrap 5 Button Groups wrap a series of buttons into a single, visually connected unit by removing the gap and border-radius between adjacent buttons. Use them when users need to choose between related actions or toggle between views: such as switching a calendar between day, week, and month layouts. They're especially effective in toolbars, filter bars, and inline form controls where space is tight and the relationship between options should be visually obvious.
Bootstrap class
.btn-groupCommon use cases
- A date range picker toolbar with 'Today', 'This Week', 'This Month', and 'Custom' buttons that filter a data table
- A text editor formatting bar grouping Bold, Italic, Underline, and Strikethrough toggle buttons
- A product listing page with 'Grid View' and 'List View' toggle buttons that switch the display layout
- A checkout form with payment method selectors ('Credit Card', 'PayPal', 'Bank Transfer') presented as a button group instead of radio buttons
Variants and classes
| Variant | Description and classes |
|---|---|
| Basic group | Buttons joined into one connected control.btn-group + btn |
| Toolbar | Several button groups side by side.btn-toolbar + btn-group |
| Sizing | Applies one size to every button in the group.btn-group btn-group-lg / btn-group-sm |
| Vertical | Buttons stacked in a column.btn-group-vertical |
| Checkbox and radio toggles | Buttons that act as checkboxes or radios.btn-check + btn btn-outline-primary |
Code example
<div class="btn-group" role="group" aria-label="View mode">
<button type="button" class="btn btn-outline-primary active">Grid View</button>
<button type="button" class="btn btn-outline-primary">List View</button>
<button type="button" class="btn btn-outline-primary">Map View</button>
</div>Live examples
Basic Button Group
Canvas template variants
Canvas Builder builds pages on the Canvas HTML template, which adds its own styled versions of Bootstrap 5 components. Variants you can ask for in a prompt:
- Canvas Builder generated button group with custom colours
- Button Group with interactive states
- Responsive button group for all screen sizes
Best practices
Always include role and aria-label
Add role="group" and a descriptive aria-label to every .btn-group wrapper. Screen readers won't announce the grouping context without it, which breaks accessibility for keyboard-only users.
Use btn-group-sm or btn-group-lg for sizing
Apply .btn-group-sm or .btn-group-lg to the wrapper element rather than adding size classes to each individual button. This keeps the sizing consistent and reduces markup clutter.
Nest groups inside a .btn-toolbar for complex controls
When you have multiple button groups that belong together, such as a text editor toolbar, wrap them in a <div class="btn-toolbar"> with role="toolbar" to create a proper composite widget with correct spacing between groups.
Avoid mixing filled and outline variants in one group
Mixing .btn-primary with .btn-outline-primary inside the same group creates jarring visual weight differences; pick one style per group so the connected border treatment renders cleanly.