Bootstrap 5 – Core UI Components
Estimated reading: 4 minutes 11 views

🔘 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 theme
  • type="button" prevents default form submit behavior

🎨 Contextual Button Colors

ClassDescription
.btn-primaryPrimary action (blue)
.btn-secondaryNeutral action (gray)
.btn-successPositive action (green)
.btn-dangerDestructive action (red)
.btn-warningCautionary action
.btn-infoInformational button
.btn-lightLight background
.btn-darkDark background
.btn-linkLooks 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 styling
  • aria-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

PracticeWhy It’s Important
Use .btn-* consistentlyKeeps UI visually uniform
Use .btn-outline-* for secondary actionsImproves contrast and visual hierarchy
Add disabled or .disabled classPrevents unintended actions
Use icons for recognizable actionsImproves usability and speed
Use .btn-group for multiple actionsBetter 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

Bootstrap 5 – Buttons & Button Groups

Or Copy Link

CONTENTS
Scroll to Top