Episode 1 — Fundamentals / 1.11 — CSS Frameworks TailwindCSS and Bootstrap

1.11.e — Introduction to Bootstrap

In one sentence: Bootstrap is a component-based CSS framework that gives you a complete design system — grid, pre-styled components, and interactive widgets — so you can build responsive layouts without writing much CSS from scratch.

Navigation: ← 1.11.d — Building with TailwindCSS · 1.11.f — Bootstrap Grid & Components →


1. What is Bootstrap?

Bootstrap is the most widely used CSS framework in history. Originally created at Twitter in 2011, it provides:

  • Pre-styled components — buttons, navbars, cards, modals, forms, alerts, tooltips
  • A 12-column responsive grid for layout
  • JavaScript plugins for interactive behavior (modals, dropdowns, carousels)
  • SASS source for deep customization
  • Utility classes (added in v5) for quick tweaks

Bootstrap 5 (current major version) dropped jQuery, added RTL support, and expanded its utility API.


2. Installation

Option A — CDN (quickest start)

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Bootstrap Demo</title>
  <!-- Bootstrap CSS -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
        rel="stylesheet" />
</head>
<body>
  <h1 class="text-center mt-5">Hello Bootstrap</h1>

  <!-- Bootstrap JS (for interactive components) -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js">
  </script>
</body>
</html>

Note: bootstrap.bundle.min.js includes Popper.js (required for tooltips, popovers, dropdowns).

Option B — npm (for build tools)

npm install bootstrap
// In your JS entry file
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';

Option C — SASS source (for customization)

npm install bootstrap
// In your SCSS file
// Override variables BEFORE importing Bootstrap
$primary: #0d6efd;
$border-radius: 0.5rem;

@import "bootstrap/scss/bootstrap";

3. The grid system — basics

Bootstrap's grid is a 12-column flexbox system with three layers:

.container  →  Centers content, sets max-width per breakpoint
  └── .row  →  Creates a flexbox row (negative margins for gutter)
       └── .col-*  →  Defines column width (1–12 units out of 12)
<div class="container">
  <div class="row">
    <div class="col-8">Main content (8/12 = 66.7%)</div>
    <div class="col-4">Sidebar (4/12 = 33.3%)</div>
  </div>
</div>

Container types

ClassBehavior
.containerFixed max-width at each breakpoint
.container-fluidFull width at all breakpoints
.container-mdFull width until md breakpoint, then fixed

4. Breakpoints

Bootstrap uses six breakpoints (mobile-first, like Tailwind):

BreakpointClass infixMin-widthExample column class
Extra small(none)0col-12
Smallsm576pxcol-sm-6
Mediummd768pxcol-md-4
Largelg992pxcol-lg-3
Extra largexl1200pxcol-xl-2
XXLxxl1400pxcol-xxl-1
<!-- Full width on mobile, half on medium, third on large -->
<div class="container">
  <div class="row">
    <div class="col-12 col-md-6 col-lg-4">Card 1</div>
    <div class="col-12 col-md-6 col-lg-4">Card 2</div>
    <div class="col-12 col-md-12 col-lg-4">Card 3</div>
  </div>
</div>

5. Key components — quick preview

Bootstrap ships dozens of ready-made components. Here are the most common:

ComponentClassWhat it does
Button.btn .btn-primaryStyled button with hover/focus states
Card.card .card-bodyBordered container with header, body, footer
Navbar.navbar .navbar-expand-lgResponsive navigation bar
Alert.alert .alert-dangerDismissible notification banner
Modal.modalDialog overlay (requires JS)
Badge.badge .bg-successSmall label/counter
Form.form-control .form-labelStyled inputs with consistent sizing
Spinner.spinner-borderLoading indicator
<!-- Button variants -->
<button class="btn btn-primary">Primary</button>
<button class="btn btn-outline-secondary">Outline</button>
<button class="btn btn-danger btn-lg">Large Danger</button>
<button class="btn btn-success btn-sm">Small Success</button>

6. Bootstrap's approach to theming

Bootstrap uses SASS variables for theming. You override variables before importing Bootstrap:

// _custom.scss
$primary:       #6366f1;  // Indigo instead of default blue
$font-family-base: "Inter", sans-serif;
$border-radius: 0.75rem;
$body-bg:       #f8fafc;

@import "bootstrap/scss/bootstrap";

Key SASS variable categories

CategoryExample variables
Colors$primary, $secondary, $success, $danger, $warning, $info
Typography$font-family-base, $font-size-base, $headings-font-weight
Spacing$spacer (base unit, default 1rem), $spacers map
Borders$border-radius, $border-width, $border-color
Breakpoints$grid-breakpoints map
Grid$grid-columns (12), $grid-gutter-width

7. Bootstrap 5 utility classes

Bootstrap 5 added a utility API that generates classes similar to Tailwind:

<div class="d-flex align-items-center justify-content-between p-3 mb-4
            bg-light rounded shadow-sm">
  <span class="fw-bold text-primary">Status</span>
  <span class="badge bg-success">Active</span>
</div>
UtilityWhat it does
d-flexdisplay: flex
d-none d-md-blockHide on mobile, show on medium+
p-3, m-2, mt-4Padding, margin
text-center, text-endText alignment
fw-bold, fs-4Font weight, font size
bg-primary, text-whiteBackground and text colors
rounded, shadow-smBorder radius, box shadow
w-100, h-autoWidth, height

These utilities complement components — use them for small tweaks without custom CSS.


8. Key takeaways

  1. Bootstrap is a component-based framework — drop in pre-styled widgets with short class names.
  2. Installation options: CDN (quickest), npm (build tools), SASS source (customization).
  3. The 12-column grid (containerrowcol-*) is the foundation of Bootstrap layout.
  4. Six breakpoints (xs through xxl) enable responsive design, mobile-first.
  5. SASS variables control theming — override them before importing Bootstrap.
  6. Bootstrap 5 includes utility classes alongside components for quick styling tweaks.

Explain-It Challenge

Explain without notes:

  1. The three layers of Bootstrap's grid system and what each does (container, row, col-*).
  2. Why you override SASS variables before the @import "bootstrap" line, not after.
  3. One advantage of Bootstrap's CDN installation and one advantage of the npm approach.

Navigation: ← 1.11.d — Building with TailwindCSS · 1.11.f — Bootstrap Grid & Components →