Master Bootstrap From Scratch

Clear, interactive, and structured Bootstrap lessons designed for beginners and developers.

Bootstrap Buttons

Bootstrap provides ready-made button classes that help us create attractive, responsive and consistent buttons for web applications.

Simple Explanation: Buttons are used to perform actions such as Submit, Save, Login, Register, Search, Delete and Cancel. Bootstrap provides different button styles, sizes, states and colors.

What is a Button?

A button is a user interface element that allows users to perform an action.

Examples of common button actions are:

  • Submit a form
  • Save information
  • Delete a record
  • Open a page
  • Search data
  • Login to an application
  • Download a file
Bootstrap buttons can be applied to <button>, <a> and <input> elements.

Basic Bootstrap Button

The .btn class is the basic Bootstrap button class.

Example

<button class="btn btn-primary">
    Click Me
</button>

Output

Bootstrap Button Colors

Bootstrap provides predefined contextual button classes for different purposes.

  • .btn-primary
  • .btn-secondary
  • .btn-success
  • .btn-danger
  • .btn-warning
  • .btn-info
  • .btn-light
  • .btn-dark
  • .btn-link

Example

<button class="btn btn-primary">
    Primary
</button>

<button class="btn btn-success">
    Success
</button>

<button class="btn btn-danger">
    Delete
</button>

<button class="btn btn-warning">
    Warning
</button>

Output

Choosing the Right Button

Different button colors can communicate different meanings to users.

Button Common Use
Primary Main action such as Submit or Save
Secondary Secondary or less important action
Success Successful or positive action
Danger Delete or destructive action
Warning Warning or caution
Info Informational action
Dark Dark-themed secondary action
Link Action that visually resembles a link

Outline Buttons

Bootstrap provides outline versions of contextual buttons. Outline buttons have a transparent background with a colored border.

The class format is:

.btn-outline-primary
.btn-outline-secondary
.btn-outline-success
.btn-outline-danger
.btn-outline-warning
.btn-outline-info
.btn-outline-dark

Example

<button class="btn btn-outline-primary">
    Primary
</button>

<button class="btn btn-outline-success">
    Success
</button>

<button class="btn btn-outline-danger">
    Delete
</button>

Output

Button Sizes

Bootstrap provides different button sizes.

  • .btn-lg - Large button
  • .btn - Normal button
  • .btn-sm - Small button

Example

<button class="btn btn-primary btn-lg">
    Large Button
</button>

<button class="btn btn-primary">
    Normal Button
</button>

<button class="btn btn-primary btn-sm">
    Small Button
</button>

Output

Full Width Button

Bootstrap's width utilities can be used to create a button that occupies the complete available width.

Example

<button class="btn btn-primary w-100">
    Submit
</button>

Output

Disabled Button

A disabled button indicates that an action is currently unavailable.

Example

<button class="btn btn-primary"
        disabled>

    Submit

</button>

Output

Button as a Link

The Bootstrap button classes can also be applied to an anchor element.

Example

<a href="#"
   class="btn btn-primary">

    View Course

</a>

Output

View Course

Button Using Input

Bootstrap button classes can also be applied to input elements.

Example

<input type="button"
       class="btn btn-primary"
       value="Click Me">

<input type="submit"
       class="btn btn-success"
       value="Submit">

<input type="reset"
       class="btn btn-danger"
       value="Reset">

Output

Button with Icon or Symbol

Text or an icon can be placed inside a Bootstrap button to make its purpose clearer.

Example

<button class="btn btn-success">
    ✓ Save
</button>

<button class="btn btn-danger">
    ✕ Delete
</button>

<button class="btn btn-primary">
    → Next
</button>

Output

Button Spacing

Bootstrap spacing utilities such as m- and gap- can be used to maintain proper spacing between buttons.

Example

<div class="d-flex gap-2">

    <button class="btn btn-primary">
        Save
    </button>

    <button class="btn btn-secondary">
        Cancel
    </button>

</div>

Output

Button States

A button can have different states depending on the situation.

  • Normal
  • Hover
  • Focus
  • Active
  • Disabled

Active Example

<button class="btn btn-primary active">
    Active
</button>

Output

Buttons Inside a Form

Buttons are frequently used inside forms for submitting, resetting or cancelling user input.

Example

<form>

    <input type="text"
           class="form-control mb-3"
           placeholder="Enter Name">

    <button type="submit"
            class="btn btn-primary">
        Submit
    </button>

    <button type="reset"
            class="btn btn-secondary">
        Reset
    </button>

</form>

Output

CIIT Training Institute Example

Let's create a practical course enquiry section using Bootstrap buttons.

.NET Full Stack Development

Learn .NET, C#, SQL Server, API, Angular, Azure and other industry-relevant technologies.

Java Full Stack Development

Learn Core Java, JDBC, Hibernate, Spring Boot, REST API and Microservices.

Real-world use: Buttons help visitors navigate courses, download information and submit enquiries.

Important Bootstrap Button Classes

Class Purpose
.btn Base Bootstrap button class
.btn-primary Primary button
.btn-success Success button
.btn-danger Danger button
.btn-warning Warning button
.btn-info Information button
.btn-dark Dark button
.btn-link Link-style button
.btn-outline-primary Primary outline button
.btn-lg Large button
.btn-sm Small button
.w-100 Full-width button

Common Mistakes

  • Forgetting the base .btn class.
  • Using a button color without considering the meaning of the action.
  • Using too many different button colors on the same page.
  • Using a destructive button such as Delete without proper confirmation in real applications.
  • Creating very small buttons that are difficult to click on mobile devices.
  • Forgetting the correct type attribute for buttons inside forms.

Summary

  • .btn is the base Bootstrap button class.
  • Bootstrap provides contextual buttons such as Primary, Success, Danger, Warning and Info.
  • Outline buttons use classes such as .btn-outline-primary.
  • .btn-lg creates a large button.
  • .btn-sm creates a small button.
  • .w-100 can be used to create a full-width button.
  • Buttons can be used with <button>, <a> and <input> elements.
  • Buttons are commonly used for forms, navigation, course pages and user actions.