Bootstrap Button Groups
Bootstrap Button Groups allow us to combine multiple buttons into a single horizontal or vertical group.
What is a Button Group?
A Button Group is a collection of related buttons placed together as one visual component.
Bootstrap provides the .btn-group class for creating Button Groups.
Button Groups are useful for:
- View / Edit / Delete actions
- Formatting controls
- Navigation options
- Filter buttons
- Course categories
- Dashboard actions
Basic Button Group
Use .btn-group as the parent container and place Bootstrap buttons inside it.
Example
<div class="btn-group">
<button class="btn btn-primary">
Left
</button>
<button class="btn btn-primary">
Middle
</button>
<button class="btn btn-primary">
Right
</button>
</div>
Output
Button Group with Different Colors
Different Bootstrap contextual button styles can be used inside the same Button Group.
Example
<div class="btn-group">
<button class="btn btn-success">
Save
</button>
<button class="btn btn-warning">
Edit
</button>
<button class="btn btn-danger">
Delete
</button>
</div>
Output
Outline Button Group
Outline button classes can also be combined inside a Button Group.
Example
<div class="btn-group">
<button class="btn btn-outline-primary">
HTML
</button>
<button class="btn btn-outline-primary">
CSS
</button>
<button class="btn btn-outline-primary">
Bootstrap
</button>
</div>
Output
Button Group Sizes
Bootstrap provides large and small Button Groups.
- .btn-group-lg - Large
- .btn-group - Normal
- .btn-group-sm - Small
Large Button Group
<div class="btn-group btn-group-lg">
<button class="btn btn-primary">
One
</button>
<button class="btn btn-primary">
Two
</button>
</div>
Output
Small Button Group
Vertical Button Group
The .btn-group-vertical class displays buttons vertically instead of horizontally.
Example
<div class="btn-group-vertical">
<button class="btn btn-primary">
Dashboard
</button>
<button class="btn btn-primary">
Courses
</button>
<button class="btn btn-primary">
Students
</button>
</div>
Output
Button Group with Links
Anchor elements can also be styled as buttons and placed inside a Button Group.
Example
<div class="btn-group">
<a href="#"
class="btn btn-primary">
Home
</a>
<a href="#"
class="btn btn-primary">
About
</a>
<a href="#"
class="btn btn-primary">
Contact
</a>
</div>
Output
Checkbox Button Group
Bootstrap can create button-style checkboxes using .btn-check.
This is useful when users can select multiple options.
Example
<input type="checkbox"
class="btn-check"
id="htmlBtn"
autocomplete="off">
<label class="btn btn-outline-primary"
for="htmlBtn">
HTML
</label>
<input type="checkbox"
class="btn-check"
id="cssBtn"
autocomplete="off">
<label class="btn btn-outline-primary"
for="cssBtn">
CSS
</label>
Output
Radio Button Group
Button-styled radio controls allow the user to select exactly one option.
Example
<input type="radio"
class="btn-check"
name="mode"
id="onlineModeBtn"
autocomplete="off">
<label class="btn btn-outline-primary"
for="onlineModeBtn">
Online
</label>
<input type="radio"
class="btn-check"
name="mode"
id="offlineModeBtn"
autocomplete="off">
<label class="btn btn-outline-primary"
for="offlineModeBtn">
Offline
</label>
Output
Button Group with Dropdown
A dropdown button can be combined with other buttons to create an advanced Button Group.
Example
<div class="btn-group">
<button class="btn btn-primary">
Course
</button>
<button class="btn btn-primary dropdown-toggle"
data-bs-toggle="dropdown">
More
</button>
<ul class="dropdown-menu">
<li>
<a class="dropdown-item" href="#">
.NET
</a>
</li>
<li>
<a class="dropdown-item" href="#">
Java
</a>
</li>
</ul>
</div>
Output
Button Toolbar
A Button Toolbar combines multiple Button Groups together using the .btn-toolbar class.
Example
<div class="btn-toolbar">
<div class="btn-group me-2">
<button class="btn btn-primary">
1
</button>
<button class="btn btn-primary">
2
</button>
<button class="btn btn-primary">
3
</button>
</div>
<div class="btn-group">
<button class="btn btn-secondary">
4
</button>
<button class="btn btn-secondary">
5
</button>
</div>
</div>
Output
CIIT Training Institute Example
Suppose CIIT Training Institute has a student management dashboard. We can use Button Groups for common student actions.
Student Actions
Course Categories
Important Button Group Classes
| Class | Purpose |
|---|---|
.btn-group |
Creates a horizontal Button Group |
.btn-group-lg |
Creates a large Button Group |
.btn-group-sm |
Creates a small Button Group |
.btn-group-vertical |
Creates a vertical Button Group |
.btn-toolbar |
Combines multiple Button Groups |
.btn-check |
Creates button-style checkbox/radio controls |
.dropdown-toggle |
Creates a dropdown button |
.btn-primary |
Primary button styling |
Common Mistakes
- Forgetting to add .btn-group around the buttons.
- Using too many unrelated actions inside the same Button Group.
- Forgetting the same name attribute for button-style radio controls.
- Using a vertical Button Group when a horizontal layout would be easier to use.
- Forgetting Bootstrap's JavaScript bundle when using dropdown functionality.
- Using too many colors inside one group and reducing visual consistency.
Summary
- .btn-group groups related buttons together.
- .btn-group-vertical displays buttons vertically.
- .btn-group-lg creates a large Button Group.
- .btn-group-sm creates a small Button Group.
- .btn-toolbar combines multiple Button Groups.
- .btn-check can create button-style checkbox and radio controls.
- Button Groups are useful for related actions such as View, Edit, Delete and course filtering.