Skip to content
Tutorials Center
My learning

Topics

Lesson 58 of 58 ยท Practice and Review

Bootstrap Cheat Sheet

A compact Bootstrap 5.3 cheat sheet: grid classes, breakpoints, spacing scale, common utilities, components and data attributes, with two live samplers.

This page is the one to keep open in a tab while you build. It does not replace the lessons; every section links to the lesson that explains the idea. You will know most of the table rows by heart soon, and when you do not, you will know where to look. Everything targets Bootstrap 5.3.3.

Starter template

HTML
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Page</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
</head>
<body>
  <div class="container">...</div>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

The bundle contains Popper. Leave the script out if the page uses no component that needs JavaScript. See Installing Bootstrap.

Breakpoints

Name Infix Min width Container max-width
Extra small (none) 0 100%
Small sm 576 px 540 px
Medium md 768 px 720 px
Large lg 992 px 960 px
Extra large xl 1200 px 1140 px
Extra extra large xxl 1400 px 1320 px

Classes with an infix apply from that width upward (mobile first). See Breakpoints and Responsive Design and Containers.

flowchart LR
  XS["xs<br/>0"] --> SM["sm<br/>576"] --> MD["md<br/>768"] --> LG["lg<br/>992"] --> XL["xl<br/>1200"] --> XXL["xxl<br/>1400"]

Each breakpoint inherits the rules of the ones to its left.

Grid classes

Goal Classes
Centered, fixed-width wrapper container
Always full width container-fluid
Full width until a breakpoint container-md (any infix)
Row of columns row
Equal-width columns col
Width by content col-auto
Span n of 12 columns col-6, col-md-4
Equal columns per row row-cols-1 row-cols-md-3
Gutters g-3, gx-4, gy-2, g-0
Vertical alignment in a row align-items-start, -center, -end
Horizontal distribution justify-content-between, -center, -around
Reorder order-1, order-md-last
Push right offset-md-2, ms-auto
Force a wrap <div class="w-100"></div> inside the row

See The Grid System, Responsive Columns and Gutters, Alignment and Ordering.

Spacing scale

The pattern is {m|p}{side}-{breakpoint}-{size}.

Size Value
0 0
1 0.25 rem
2 0.5 rem
3 1 rem
4 1.5 rem
5 3 rem
auto auto (margins only)
Side Meaning
t, b top, bottom
s, e start, end (left and right in left-to-right text)
x, y both horizontal or both vertical sides
none all four sides

gap-3 sets the gap on flex and grid containers. Negative margins exist as mt-n3-style classes only when enabled in Sass. See Spacing Utilities.

Common utilities

Area Classes
Display d-none, d-block, d-inline, d-flex, d-md-none, d-print-none
Flex flex-row, flex-column, flex-wrap, flex-grow-1, flex-fill
Text text-start, text-center, text-end, text-truncate, text-nowrap, text-uppercase
Font fw-bold, fw-semibold, fst-italic, fs-1 to fs-6, lh-1
Color text-primary, text-body-secondary, bg-primary, bg-success-subtle, text-bg-dark
Border border, border-top, border-0, border-2, rounded, rounded-pill, rounded-circle
Shadow shadow-sm, shadow, shadow-lg, shadow-none
Sizing w-25, w-50, w-100, h-100, mw-100, vh-100
Position position-relative, position-absolute, fixed-top, sticky-top, top-0, start-50
Visibility visible, invisible, visually-hidden

Theme color names for text-*, bg-*, btn-*, alert-* and border-* are primary, secondary, success, danger, warning, info, light and dark. See Flex Utilities, Colors and Backgrounds and Borders, Radius and Shadows.

Utilities sampler

Components at a glance

Component Core classes Needs JS?
Button btn btn-primary, btn-outline-*, btn-lg, btn-sm no
Button group btn-group, btn-toolbar no
Card card, card-body, card-title, card-footer, card-img-top no
Navbar navbar navbar-expand-lg, navbar-brand, navbar-nav, nav-link toggler only
Nav and tabs nav nav-tabs, nav-pills, tab-content, tab-pane tabs only
Alert alert alert-warning, alert-dismissible, btn-close dismiss only
Badge badge text-bg-* no
Progress progress, progress-bar no
Spinner spinner-border, spinner-grow no
List group list-group, list-group-item, list-group-flush no
Breadcrumb breadcrumb, breadcrumb-item, aria-current="page" no
Pagination pagination, page-item, page-link no
Accordion accordion, accordion-item, accordion-button yes
Modal modal, modal-dialog, modal-content, modal-body yes
Dropdown dropdown, dropdown-menu, dropdown-item yes
Tooltip, popover data-bs-toggle="tooltip" and "popover" yes, opt-in
Carousel carousel slide, carousel-item, carousel-control-prev yes
Offcanvas offcanvas offcanvas-start yes
Toast toast, toast-container yes

Lessons: Buttons, Cards, The Navbar, Navs and Tabs, Alerts, Badges, Progress and Spinners, List Groups, Breadcrumbs and Pagination, Accordion and Collapse, Modals, Dropdowns, Tooltips and Popovers and Carousel, Offcanvas and Toasts.

Forms

Control Classes
Text input, textarea form-control with form-label
Select form-select
Checkbox, radio form-check, form-check-input, form-check-label
Switch form-check form-switch
Range form-range
Help text form-text
Size form-control-lg, form-control-sm, form-select-lg
Input group input-group, input-group-text
Floating label form-floating (input first, label second)
Validation needs-validation + novalidate, was-validated, is-valid, is-invalid, invalid-feedback

See Form Controls, Selects, Checks, Switches and Ranges, Input Groups and Floating Labels and Form Layout and Validation.

Data attributes

Attribute Used on Meaning
data-bs-toggle trigger Which plugin: collapse, modal, dropdown, tab, pill, offcanvas, tooltip, popover
data-bs-target trigger Selector of the element to control, such as #menu
data-bs-dismiss button inside Closes the parent: modal, alert, toast, offcanvas
data-bs-parent collapse Selector of the accordion wrapper, so only one panel stays open
data-bs-backdrop modal, offcanvas true, false or static
data-bs-keyboard modal, offcanvas false ignores Escape
data-bs-ride carousel carousel to start automatically
data-bs-slide, data-bs-slide-to carousel controls prev/next, or an index
data-bs-title, data-bs-content tooltip, popover The text
data-bs-placement tooltip, popover top, bottom, start, end
data-bs-theme any element light or dark color mode
data-bs-spy scrollspy container scroll

Options can also be set from JavaScript, and events are named like show.bs.modal. See Bootstrap JavaScript Plugins and Plugin Events and Programmatic Control.

Data attributes in action

CSS variables worth remembering

Variable What it controls
--bs-primary, --bs-success, ... Theme colors
--bs-body-bg, --bs-body-color Page background and text
--bs-body-font-family, --bs-body-font-size Base typography
--bs-border-radius Default corner radius
--bs-gutter-x Column gutter (set by g-*)
--bs-btn-bg, --bs-btn-color, ... Per-button overrides

See Customizing with CSS Variables and Color Modes and Dark Mode.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Which spacing class gives an element 1.5 rem of padding on the left and right only?

    x means both horizontal sides, and size 4 is 1.5 rem. py-4 is vertical and ps-5 is 3 rem on the start side only.
  2. 2. Which attribute names the element that a button should open or toggle?

    data-bs-target holds a selector such as #menu. data-bs-parent is for accordions and data-bs-dismiss closes.
  3. 3. At what minimum width does the lg breakpoint start?

    lg starts at 992px; md starts at 768px and xl at 1200px.

Summary

  • The six breakpoints are 0, 576, 768, 992, 1200 and 1400 px; classes apply upward.
  • A row has 12 units; col-*, row-cols-*, g-* and the alignment classes shape it.
  • Spacing runs 0 to 5 (0 to 3 rem) with auto for margins; x, y, s, e, t, b pick the sides.
  • Components need the bundle only when they open, close or move: collapse, modal, dropdown, carousel, offcanvas, toast, tooltip, popover.
  • data-bs-* attributes wire the plugins without custom code.

That is the end of the track. Return to Introduction to Bootstrap to review anything, or practice again with the exercises.