Lesson 15 of 60 – Bootstrap Buttons
25%

Bootstrap Buttons

Bootstrap provides ready-made button styles that make it easy to create attractive, consistent, and responsive buttons. Buttons can be used for submitting forms, opening pages, performing actions, showing messages, and many other purposes.

Note: Bootstrap buttons are created using the .btn class together with a contextual class such as .btn-primary, .btn-success, or .btn-danger.

1. What Are Bootstrap Buttons?

Bootstrap buttons are predefined CSS styles used to create professional looking buttons without writing a lot of custom CSS.

Example:

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

The .btn class provides the basic button styling, while .btn-primary defines the button's contextual appearance.

2. Basic Bootstrap Button

The simplest Bootstrap button uses the .btn class. Usually, it is combined with a contextual button class.

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

Bootstrap provides consistent padding, border radius, font styling, and other visual properties.

3. Primary Button

The .btn-primary class is commonly used for the main or important action on a page.

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

Primary buttons are useful for actions such as Save, Submit, Continue, Login, and Next.

4. Success Button

The .btn-success class is generally used for successful or positive actions.

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

For example, you can use it for Confirm, Complete, Approve, or Save actions.

5. Danger Button

The .btn-danger class is commonly used for destructive or dangerous actions.

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

It can be used for Delete, Remove, Cancel, or other actions that need extra attention.

6. Warning Button

The .btn-warning class creates a warning-style button.

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

Warning buttons can be used when an action requires user attention.

7. Info Button

The .btn-info class creates an informational button.

<button class="btn btn-info">More Info</button>

It can be useful for actions such as More Info, Details, or Help.

8. Light Button

The .btn-light class creates a light-colored button.

<button class="btn btn-light">Light Button</button>

Light buttons are useful on darker backgrounds.

9. Dark Button

The .btn-dark class creates a dark button.

<button class="btn btn-dark">Dark Button</button>

Dark buttons are useful when you want strong visual contrast.

10. Secondary Button

The .btn-secondary class is useful for secondary actions.

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

For example, a form may use a primary button for Submit and a secondary button for Cancel.

11. Link Button

Bootstrap can style an anchor element as a button.

<a href="#" class="btn btn-primary">
Go to Page
</a>
Go to Page

This is useful when clicking the button should navigate to another page.

12. Outline Buttons

Bootstrap provides outline button classes that display a transparent background with a colored border.

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

Outline buttons are useful when you want less visual emphasis.

13. Different Outline Buttons

Bootstrap provides outline versions for several contextual colors.

<button class="btn btn-outline-success">Success</button>
<button class="btn btn-outline-danger">Delete</button>
<button class="btn btn-outline-warning">Warning</button>
<button class="btn btn-outline-dark">Dark</button>

14. Large Buttons

The .btn-lg class creates a larger button.

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

Large buttons can be useful for important actions or prominent areas.

15. Small Buttons

The .btn-sm class creates a smaller button.

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

Small buttons can be useful in tables, dashboards, and compact interfaces.

16. Normal Button Size

If you do not use .btn-lg or .btn-sm, Bootstrap uses the normal button size.

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

The normal size is suitable for most common interface actions.

17. Disabled Buttons

A button can be disabled using the HTML disabled attribute.

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

A disabled button cannot normally be clicked or activated by the user.

18. Disabled Link Buttons

For anchor elements, Bootstrap provides the .disabled class to visually indicate that the link is disabled.

<a href="#" class="btn btn-primary disabled">
Disabled Link
</a>
Disabled Link

Remember that .disabled on a link is mainly a visual and interaction state. Proper application logic may still be required.

19. Full Width Button

Bootstrap utilities can be combined with buttons to make them occupy the available width.

<button class="btn btn-primary w-100">
Full Width Button
</button>

The w-100 utility sets the width to 100%.

20. Button with Icons

Icons can be placed inside buttons to make their purpose easier to understand.

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

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

You can use Bootstrap Icons or another icon library when your project includes one.

21. Multiple Buttons

Multiple Bootstrap buttons can be placed next to each other.

<button class="btn btn-primary">Save</button>
<button class="btn btn-secondary">Cancel</button>
<button class="btn btn-danger">Delete</button>

22. Button Groups

The .btn-group class combines multiple buttons into a single connected group.

<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>

23. Vertical Button Group

The .btn-group-vertical class displays buttons vertically.

<div class="btn-group-vertical">
    <button class="btn btn-primary">Home</button>
    <button class="btn btn-primary">About</button>
    <button class="btn btn-primary">Contact</button>
</div>

24. Buttons in Forms

Bootstrap buttons are commonly used with HTML forms.

<form>

<input type="text"
class="form-control mb-2"
placeholder="Enter your name">

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

</form>

25. Button Types

HTML provides different button types. The most common types are button, submit, and reset.

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

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

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

Choosing the correct HTML button type is important when working with forms.

26. Button Colors Example

Bootstrap provides several contextual button classes.

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

27. Combining Button Classes

Bootstrap classes can be combined to create different button sizes and styles.

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

<button class="btn btn-outline-success btn-sm">
Small Outline
</button>

<button class="btn btn-danger w-100 mt-2">
Full Width
</button>

28. Button Accessibility

Buttons should have clear text that explains what will happen when the user clicks them.

Good examples:

  • Save Changes
  • Submit Form
  • Delete Account
  • Download File
  • View Details

Avoid unclear labels such as only "Click Here" when a more descriptive label can be used.

Tip: Choose button text that clearly communicates the action.

29. Practical Button Example

Here is a simple example of buttons commonly used in an admin panel.

<div class="mb-3">

    <button class="btn btn-primary">
        Add Student
    </button>

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

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

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

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

</div>

This type of button arrangement is frequently used in dashboards, management systems, and CRUD applications.

30. Complete Bootstrap Button Example

The following example combines several Bootstrap button features.

<div class="container mt-4">

    <h3>Student Management</h3>

    <button class="btn btn-primary">
        Add Student
    </button>

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

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

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

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

</div>
Student Management

This example demonstrates how Bootstrap buttons can be used to create a simple and professional action area.

📌 Key Points

  • Use .btn as the basic Bootstrap button class.
  • Use contextual classes such as .btn-primary and .btn-success.
  • Use .btn-danger for destructive actions.
  • Use .btn-outline-* for outline buttons.
  • Use .btn-lg for large buttons.
  • Use .btn-sm for small buttons.
  • Use disabled for disabled HTML buttons.
  • Use w-100 for a full-width button.
  • Use .btn-group to group buttons.
  • Use .btn-group-vertical for vertical groups.
  • Use clear and meaningful button text.

🧠 Quick Quiz

Question: Which Bootstrap class creates a primary button?