Bootstrap 5 Button Group
A Bootstrap 5 Button Group wraps a series of buttons into a single horizontal (or vertical) control, removing the gaps between them and optionally giving them a shared border. Use it when you need a set of related actions — like filter options, view toggles, or segmented controls — that belong together visually and functionally. It differs from a toolbar in that a single group represents one logical choice set, not a collection of disparate tools.
Primary Class
.button-groupCommon Use Cases
- →Toggling between table view, grid view, and list view on a product listing page — each button switches the display mode and the active state highlights the current selection
- →A date range selector with preset options (Today, This Week, This Month, Custom) inside a dashboard analytics panel, replacing a dropdown with always-visible choices
- →A text editor toolbar segment for inline formatting — Bold, Italic, Underline — where users expect the buttons to be visually joined rather than spaced apart
- →A quantity selector in an e-commerce product page combining a decrement button, a readonly input showing the count, and an increment button inside an input group variant of the button group
Variants & Classes
| Variant | Description |
|---|---|
| Button Group Default | Standard button group with Bootstrap's default styling. |
| Button Group Responsive | Responsive variant that adapts to different screen sizes. |
Code Example
<div class="btn-group" role="group" aria-label="View options"> <input type="radio" class="btn-check" name="viewOptions" id="viewGrid" autocomplete="off" checked> <label class="btn btn-outline-primary" for="viewGrid">Grid</label> <input type="radio" class="btn-check" name="viewOptions" id="viewList" autocomplete="off"> <label class="btn btn-outline-primary" for="viewList">List</label> <input type="radio" class="btn-check" name="viewOptions" id="viewTable" autocomplete="off"> <label class="btn btn-outline-primary" for="viewTable">Table</label> </div>
Live Examples
Basic Button Group
Canvas Framework Variants
The Canvas template extends Bootstrap 5 with 1,658+ component variants. Generate any of these using Canvas Builder:
- ✓Canvas Builder generated button group with custom colours
- ✓Button Group with interactive states
- ✓Responsive button group for all screen sizes
Best Practices
Always add role and aria-label
Screen readers won't understand the grouping unless you add `role="group"` and a descriptive `aria-label` to the wrapper div — Bootstrap doesn't inject these automatically, so leaving them out fails WCAG 2.1.
Use btn-check for true toggle behaviour
Pair `<input type="radio">` or `<input type="checkbox">` with the `btn-check` class and a corresponding `<label class="btn">` — this gives you native form state (checked/unchecked) without any JavaScript, and the active highlight is handled by CSS alone.
Size the whole group, not individual buttons
Apply `btn-group-lg` or `btn-group-sm` to the wrapper element rather than adding size classes to each button — this keeps sizing consistent and reduces markup clutter.
Nest dropdown menus inside a button group cleanly
You can place a `<div class="btn-group">` inside another `btn-group` to embed a dropdown trigger mid-group — this is the correct Bootstrap pattern for a split button, keeping the action button and its dropdown arrow as separate focusable elements.