Skip to main content

Bootstrap Guide

This is a practical cheat sheet for using Bootstrap effectively in real projectsβ€”focused on when to use components, how to use them, and best practices.


🎯 What is Bootstrap?

Bootstrap is a CSS framework that provides:

  • Prebuilt UI components (buttons, cards, navbars)
  • Utility classes (spacing, colors, layout)
  • Responsive grid system

It helps you build interfaces faster without writing everything from scratch.


🧠 When to Use Bootstrap

Use Bootstrap when:

  • You want fast UI development
  • You need responsive design
  • You don’t want to write custom CSS for everything

Avoid overusing Bootstrap when:

  • You need highly custom animations
  • You want a fully unique design system

πŸ“¦ Core Concepts

1. Container System​

<div class="container">
Content here
</div>

### Variants:
- container β†’ fixed width
- container-fluid β†’ full width

---

## 2. Grid System
Bootstrap uses a 12-column layout.
```bash
<div class="row">
<div class="col-md-6">Left</div>
<div class="col-md-6">Right</div>
</div>

Breakpoints:

  • col-sm-* β†’ small devices
  • col-md-* β†’ tablets
  • col-lg-* β†’ desktops

🎨 Buttons (VERY IMPORTANT)

Basic Syntax

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

Button Types (When to Use)​

ClassColorUse Case
btn-primaryBlueMain action (Save, Submit)
btn-secondaryGraySecondary action
btn-successGreenConfirm, Approve
btn-dangerRedDelete, Remove
btn-warningYellowEdit, Warning
btn-infoLight BlueInfo, View
btn-lightWhiteNeutral UI
btn-darkBlackStrong contrast

Examples​

Primary Action​

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

Delete Action​

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

Edit Action​

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

Button Sizes​

btn-lg β†’ large
btn-sm β†’ small

Example:
```bash
<button class="btn btn-primary btn-sm">Small Button</button>

🎨 Colors (Utilities)

Bootstrap includes color utility classes:

Text Colors​

text-primary
text-success
text-danger
text-warning
text-info
text-muted

Background Colors​

bg-primary
bg-success
bg-danger
bg-warning
bg-info
bg-light
bg-dark

Example​

<div class="bg-primary text-white p-3">
Important Section
</div>

πŸ“ Spacing System

Bootstrap uses a spacing scale:

Format:

m = margin
p = padding
t = top
b = bottom
s = start (left)
e = end (right)
x = left/right
y = top/bottom

Examples​

mt-3 β†’ margin-top mb-4 β†’ margin-bottom px-5 β†’ padding left/right py-3 β†’ padding top/bottom


🧱 Common Components​

Cards​

<div class="card">
<div class="card-body">
Content here
</div>
</div>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
Navbar content
</nav>

Alerts​

<div class="alert alert-success">
Success message
</div>

πŸ’‘ Best Practices​

  • βœ” Use Bootstrap for layout first
  • βœ” Only add custom CSS for branding
  • βœ” Keep spacing consistent (py-5, mb-4)
  • βœ” Use button colors consistently (don’t mix meanings)
  • βœ” Prefer utility classes over custom CSS

πŸš€ Quick Mental Model​

Think like this:

  • btn-primary β†’ main action
  • btn-danger β†’ destructive action
  • btn-warning β†’ edit/change
  • btn-success β†’ confirm/complete

πŸ“Œ Summary​

Bootstrap helps you:

  • Build faster
  • Stay consistent
  • Avoid repetitive CSS

But the key is using it consistently and intentionally, not randomly.