mc0de
mC0de / Bootstrap Elements / Lesson 01 of 07

Bootstrap Buttons

Small elements. Big impact. Learn how Bootstrap transforms ordinary HTML buttons into polished, responsive components using simple CSS classes.

Beginner Friendly Bootstrap 5.3 Hands-On Challenge Live Sandbox
buttons.html
<button
  class="btn btn-primary">
  Get Started
</button>

<button
  class="btn btn-outline-success">
  Learn More
</button>
Get Started → Learn More
01 / Getting Started

What Are Bootstrap Buttons?

A button is one of the most common elements on a website. It can submit a form, confirm a choice, start an action, or help visitors move through an interface.

Bootstrap is a front-end toolkit that provides ready-made styles. Instead of writing custom CSS for every button, you can apply Bootstrap classes directly to HTML elements.

Remember: Bootstrap classes control how a button looks. They do not automatically give it an action. You’ll still use HTML, JavaScript, or a form to decide what happens when someone clicks it.
02 / The Basics

Your First Bootstrap Button

A Bootstrap button usually starts with two classes: btn and a style such as btn-primary.

<button type="button" class="btn btn-primary">
  Click Me
</button>
btn Applies the basic Bootstrap button structure, padding, and alignment.
btn-primary Adds the familiar blue primary button appearance.

For Bootstrap styling to work, your page must load the Bootstrap CSS file. Our Sandbox handles this automatically so you can focus on learning.

03 / Button Variants

Choose the Right Button Color

Bootstrap includes several button variants. The class name communicates the visual purpose of the button, such as a primary action, success, or warning.

<button class="btn btn-primary" type="button">Primary</button>
<button class="btn btn-secondary" type="button">Secondary</button>
<button class="btn btn-success" type="button">Success</button>
<button class="btn btn-danger" type="button">Danger</button>

Other built-in variants include btn-warning, btn-info, btn-light, btn-dark, and btn-link.

Design tip: Choose colors based on the meaning of the action. Don’t rely on color alone: clear button text matters for accessibility.
04 / Outline Styles

Make Outline Buttons

Outline buttons have a transparent background and colored border. They work well for secondary actions that shouldn’t compete with the main button.

<button type="button" class="btn btn-outline-primary">
  Learn More
</button>

Try replacing btn-outline-primary with btn-outline-success or btn-outline-danger.

05 / Sizing

Small, Regular, or Large?

Bootstrap has three common button sizes. The regular size needs no extra class. Add btn-sm for small buttons or btn-lg for large ones.

<button class="btn btn-primary btn-sm" type="button">Small</button>
<button class="btn btn-primary" type="button">Regular</button>
<button class="btn btn-primary btn-lg" type="button">Large</button>
06 / Button States

Disable a Button

Sometimes an action shouldn’t be available yet. Add the HTML disabled attribute to prevent a button from being activated.

<button type="button" class="btn btn-secondary" disabled>
  Not Available
</button>
Important: The disabled attribute works on HTML buttons, not ordinary links. For navigation, use a real <a> link with an href instead.
07 / Layout

Create Full-Width Buttons

Bootstrap 5 uses layout utilities to create full-width buttons. Wrap the button in a container with the d-grid class.

<div class="d-grid">
  <button type="button" class="btn btn-primary">
    Continue
  </button>
</div>

You can also add gap-2 when stacking multiple buttons to create space between them.

Your Turn / Practice Time

🚀 mC0de Challenge

Build a Mini Action Panel

Imagine you’re designing a simple dashboard. Your job is to create a collection of buttons with different purposes, appearances, and sizes.

Your mission: Complete all five tasks in the Sandbox below.

The checklist is for self-review. Experiment freely, then compare your result with the sample solution.

Interactive Coding Workspace

mC0de Bootstrap Sandbox

Edit the HTML, run your code, and watch Bootstrap style your buttons.

HTML Input / buttons.html
Live Result / Bootstrap 5.3
Ready to code. Press Run Code or edit the HTML to preview.
Lesson Recap

✓ What You’ve Learned

  • Bootstrap makes button styling easier through reusable CSS classes.
  • The btn class provides the basic button foundation.
  • Variants such as btn-primary and btn-success add color.
  • btn-outline-* creates outline-style buttons.
  • btn-sm and btn-lg change button size.
  • The disabled attribute makes a button unavailable.
  • Bootstrap’s d-grid utility helps create full-width buttons.

Up next: We’ll build a responsive Navigation Bar using Bootstrap.

Your Learning Journey
Bootstrap Elements Learning Path 0 of 7 completed
Lesson 01 / Buttons 0% Complete

Nice Work! 🎉

You’ve learned how to create and customize Bootstrap buttons. Ready to add this lesson to your completed learning path?

Lesson 01 of 07 · Bootstrap Elements