Bootstrap 5 Introduction
Bootstrap is the most widely used front-end toolkit for building responsive, mobile-first websites. It is a ready-made collection of CSS classes and a little JavaScript: instead of writing your own styles for buttons, grids, menus and forms, you add Bootstrap's class names to plain HTML and get a polished, consistent result.
Bootstrap was created at Twitter in 2011 by Mark Otto and Jacob Thornton. This course teaches Bootstrap 5.3, the current major version.
What Bootstrap gives you
| Part | What it is | Example classes |
|---|---|---|
| Layout | Containers and a 12-column responsive grid | container, row, col-md-6 |
| Content | Nicer defaults for text, tables, images | lead, table, img-fluid |
| Components | Ready-made UI pieces | btn, card, navbar, modal |
| Forms | Consistent inputs, selects, checks, validation | form-control, form-check |
| Utilities | Single-purpose helper classes | mt-3, text-center, d-flex |
| JavaScript plugins | Behaviour for interactive components | dropdowns, collapse, carousel, tooltips |
Your first Bootstrap page
The page below is plain HTML. The only "magic" is the <link> to Bootstrap's stylesheet and the class names. Press ▶ Run, then try changing btn-primary to btn-success.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container py-4">
<h1 class="display-6">Hello, Bootstrap! 👋</h1>
<p class="lead">This page has no custom CSS at all.</p>
<button class="btn btn-primary">A Bootstrap button</button>
<button class="btn btn-outline-secondary">Another one</button>
</div>
</body>
</html>Same HTML, with and without Bootstrap
To see how much Bootstrap does, compare the raw browser defaults with Bootstrap's styling. The second half of the example below is identical markup, just with classes added.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="row g-3">
<div class="col-6">
<h5>Classes only</h5>
<input class="form-control mb-2" placeholder="Your email">
<button class="btn btn-primary w-100">Subscribe</button>
</div>
<div class="col-6">
<h5>Plus a card</h5>
<div class="card shadow-sm">
<div class="card-body">
<input class="form-control mb-2" placeholder="Your email">
<button class="btn btn-success w-100">Subscribe</button>
</div>
</div>
</div>
</div>
</body>
</html>Why use Bootstrap?
- Fast to build with – a working, good-looking layout in minutes.
- Responsive by default – the grid and many components adapt to phones, tablets and desktops.
- Consistent – spacing, colours and typography follow one design system.
- Accessible foundations – components ship with sensible ARIA patterns and keyboard support.
- Customisable – every colour and size is a CSS variable (or a Sass variable if you compile it yourself).
- No jQuery – Bootstrap 5 dropped jQuery; its plugins are plain JavaScript.
Mobile-first
Bootstrap is mobile-first: its base styles target small screens, and media queries add layout changes as the screen gets wider. A class like col-md-6 means "half width from the medium breakpoint (768px) and up"; below that the column is full width.
| Breakpoint | Class infix | Minimum width |
|---|---|---|
| Extra small | (none) | 0 |
| Small | sm |
576px |
| Medium | md |
768px |
| Large | lg |
992px |
| Extra large | xl |
1200px |
| Extra extra large | xxl |
1400px |
Note: The preview frame under each example is as wide as the lesson column, which is narrower than a full desktop window. Breakpoints react to the frame's width, not the screen's. To see responsive changes, resize your browser window — the frame follows the column. You can also drag the frame's bottom-right corner to make it taller.
What changed from Bootstrap 4?
| Bootstrap 4 | Bootstrap 5 |
|---|---|
| Needed jQuery | Vanilla JavaScript |
data-toggle="…" |
data-bs-toggle="…" (namespaced) |
ml-* / mr-* |
ms-* / me-* (start/end, RTL-friendly) |
| Jumbotron component | Removed — build heroes with utilities |
No xxl breakpoint |
xxl added (1400px) |
| Light theme only | Colour modes with data-bs-theme (5.3) |
Tip: Bootstrap doesn't replace CSS. Knowing the box model, Flexbox and media queries makes Bootstrap much easier to understand, because its classes are thin wrappers around those features.
Test yourself
What does "mobile-first" mean in Bootstrap?
- It only works on phones
- Base styles target small screens and media queries add changes for wider screens
- Desktop styles are written first and removed for phones
- It requires a mobile app
Which library does Bootstrap 5 no longer depend on?
- Popper
- Sass
- jQuery
- Normalize
How are Bootstrap 5's data attributes named?
- data-toggle
- data-bs-toggle
- bs-toggle
- data-bootstrap