🔘 Bootstrap 5 – Buttons & Button Groups: Style Actions the Right Way
🧲 Introduction – Why Use Bootstrap Buttons?
Buttons are critical for user interaction—form submissions, actions, toggles, and more. Bootstrap 5 provides pre-styled, responsive, and accessible button components with utility classes for size, color, shape, and groupings.
🎯 In this guide, you’ll learn:
- How to use
.btn
and contextual.btn-*
classes - Modify button sizes, states, and outlines
- Create grouped buttons horizontally and vertically
- Combine buttons with dropdowns and toolbars
✅ Example 1 – Basic Bootstrap Button
<button type="button" class="btn btn-primary">Primary</button>
🔍 Explanation:
.btn
: Base class for all Bootstrap buttons.btn-primary
: Applies blue color from the themetype="button"
prevents default form submit behavior
🎨 Contextual Button Colors
Class | Description |
---|---|
.btn-primary | Primary action (blue) |
.btn-secondary | Neutral action (gray) |
.btn-success | Positive action (green) |
.btn-danger | Destructive action (red) |
.btn-warning | Cautionary action |
.btn-info | Informational button |
.btn-light | Light background |
.btn-dark | Dark background |
.btn-link | Looks like a hyperlink |
✅ Example 2 – Outline Buttons
<button class="btn btn-outline-success">Outline Success</button>
🔍 Explanation:
.btn-outline-*
: Only border and text color, no background- Great for subtle UI components or secondary actions
✅ Example 3 – Button Sizes
<button class="btn btn-primary btn-lg">Large</button>
<button class="btn btn-secondary btn-sm">Small</button>
🔍 Explanation:
.btn-lg
: Makes the button larger.btn-sm
: Creates a compact button for toolbars or dense UI
✅ Example 4 – Disabled & Active Buttons
<button class="btn btn-danger" disabled>Disabled</button>
<button class="btn btn-info active" aria-pressed="true">Active</button>
🔍 Explanation:
disabled
: Disables interaction.active
: Applies pressed-state stylingaria-pressed="true"
adds accessibility support
✅ Example 5 – Block-Level Button (Full Width)
<button class="btn btn-warning w-100">Full Width</button>
🔍 Explanation:
w-100
: Sets width to 100% of the parent container
✅ Example 6 – Button Group (Horizontal)
<div class="btn-group" role="group">
<button class="btn btn-outline-primary">Left</button>
<button class="btn btn-outline-primary">Center</button>
<button class="btn btn-outline-primary">Right</button>
</div>
🔍 Explanation:
.btn-group
: Groups buttons side-by-side- Useful for toggle options, toolbars, navigation
✅ Example 7 – Button Group (Vertical)
<div class="btn-group-vertical" role="group">
<button class="btn btn-secondary">Top</button>
<button class="btn btn-secondary">Middle</button>
<button class="btn btn-secondary">Bottom</button>
</div>
🔍 Explanation:
.btn-group-vertical
: Stacks buttons vertically- Great for sidebars or vertical controls
✅ Example 8 – Button with Icon (Bootstrap Icons)
<button class="btn btn-success">
<i class="bi bi-check-circle me-1"></i> Confirm
</button>
🔍 Explanation:
- Combine Bootstrap Icons with buttons
me-1
adds margin for spacing between icon and text
🛠️ Best Practices for Bootstrap 5 Buttons
Practice | Why It’s Important |
---|---|
Use .btn-* consistently | Keeps UI visually uniform |
Use .btn-outline-* for secondary actions | Improves contrast and visual hierarchy |
Add disabled or .disabled class | Prevents unintended actions |
Use icons for recognizable actions | Improves usability and speed |
Use .btn-group for multiple actions | Better layout and interaction grouping |
📌 Summary – Button Styling Made Easy with Bootstrap 5
Bootstrap 5 gives you full control over button appearance and behavior. With built-in classes for color, size, grouping, and alignment, you can create intuitive, modern UI components for any interface.
🔍 Key Takeaways:
- Use
.btn
and.btn-*
for styled buttons - Use
.btn-outline-*
for bordered alternatives - Use
.btn-group
and.btn-group-vertical
for organizing actions - Combine icons, full-width utilities, and states for advanced UIs
⚙️ Ideal for forms, toolbars, dashboards, product cards, and modals.
❓ FAQs – Bootstrap 5 Buttons & Button Groups
❓ What is the difference between .btn
and .btn-outline-*
?
✅ .btn
includes a background color, whereas .btn-outline-*
uses a transparent background and colored border.
❓ How can I make a button full width?
✅ Add w-100
to the button:
<button class="btn btn-primary w-100">Full Width</button>
❓ Can I use icons inside buttons?
✅ Yes! You can use Bootstrap Icons or SVGs inside buttons alongside text.
❓ Can buttons be grouped with dropdowns?
✅ Yes. Use .btn-group
along with .dropdown-toggle
for combining actions and menus.
Share Now :