Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 58 ยท Getting Started

Your First Bootstrap Page

Build a first Bootstrap 5 page, see what Reboot changes (box-sizing, fonts, margins) and learn how class names such as container and btn map to real CSS.

You have Bootstrap loading; now it is time to build something. In this lesson you will create a small page with a container, a heading, some text and a button, and you will look closely at what Bootstrap quietly changed before you added a single class. Understanding Reboot, the built-in reset, explains many "why does it look like this?" moments later on.

If you have not set up the CDN links yet, read Installing Bootstrap first. The editors in this tutorial already include them.

Reboot: the quiet first layer

Browsers ship with their own default styles (a bit of margin on body, big margins on headings, different fonts per operating system). These defaults differ between browsers, which makes pages look slightly different everywhere. Bootstrap loads a stylesheet section called Reboot that builds a consistent starting point. The most important changes:

  • box-sizing: border-box on every element. Width and height now include padding and border. A box with width: 200px; padding: 20px stays 200px wide instead of growing to 240px. This one rule removes a whole class of layout headaches.
  • A system font stack. The page uses the font of the user's operating system (San Francisco on Apple devices, Segoe UI on Windows, Roboto on Android), so text looks native and loads instantly because no font file is downloaded.
  • Base text settings. body gets font-size: 1rem (usually 16px), line-height: 1.5, and it uses theme colors for text and background (these switch in dark mode).
  • No margin on body. The page touches the browser edge. That is why most content sits inside a container, which adds the sideways space back.
  • Simple vertical rhythm. Headings, paragraphs and lists only get margin at the bottom (margin-bottom: 1rem for paragraphs, .5rem for headings). Margins no longer collapse in confusing ways.
  • Links are blue and underlined, tables collapse their borders, img is a block-friendly element and form controls inherit the page font instead of using tiny browser defaults.

The next example shows the effect of border-box. Both boxes are given the same width and padding. The first uses Bootstrap's behavior, the second is switched back to the browser's old default with an inline style.

Border-box: the same width, different result

Build the page

A Bootstrap page is mostly structure plus class names. Here is the pattern you will repeat hundreds of times:

  1. A container centers your content and gives it side padding.
  2. Inside it, normal HTML elements (h1, p, button) do the work.
  3. Extra utility classes adjust spacing and appearance (py-4, mb-3, text-center).
  4. Component classes (btn btn-primary) style whole controls.
A first complete page

Read the code once more. There is not a single line of custom CSS, yet the page has a readable width, sensible spacing and styled buttons.

How classes map to CSS

A class name in Bootstrap is a label for a bundle of CSS declarations. Nothing magic happens; the stylesheet simply contains a rule for each label. Some examples (simplified):

Class What it does in CSS
.mb-3 margin-bottom: 1rem !important;
.py-5 padding-top: 3rem; padding-bottom: 3rem; (both with !important)
.text-center text-align: center !important;
.d-flex display: flex !important;
.btn padding, border, font size, radius, cursor, hover and focus states
.container width: 100%, side padding, margin-inline: auto and a max-width per breakpoint

Utilities such as mb-3 use !important on purpose, so they win over component styles. Components such as .btn contain many declarations and also use CSS variables (names starting with --bs-), which is how Bootstrap makes theming possible. You can see those variables in your browser's DevTools: select a button and look at --bs-btn-bg and friends.

flowchart LR
  H["HTML: class='btn btn-primary'"] --> S["Stylesheet rules<br/>.btn, .btn-primary"]
  S --> V["CSS variables<br/>--bs-btn-bg, --bs-btn-color"]
  V --> R["What you see:<br/>a blue rounded button"]

Class names select rules; the rules read CSS variables; the browser paints the result.

Combine classes, do not repeat styles

Because every class does one job, you combine them instead of writing new CSS. Compare writing a custom class with Bootstrap's approach:

HTML
<!-- Custom CSS you would have to write and maintain -->
<div class="promo-box">...</div>

<!-- Bootstrap: compose existing classes -->
<div class="p-4 mb-3 bg-light border rounded">...</div>

If you later want more space, you change p-4 to p-5. No stylesheet edit is needed. This composing habit is the heart of Bootstrap and is explored fully in the spacing and utility lessons.

Seeing the structure with a card of notes

Here is one more example that uses a few new classes together: a background color, a border, rounded corners and a shadow. Read each class name aloud, and you can predict what it does.

Composing utility classes

Notice h2 class="h4": Bootstrap lets you give a heading the look of another level (h4) while keeping the meaning (h2) correct for accessibility and SEO. This is covered in the typography lesson.

Margins and paddings in Bootstrap use rem units, so they scale with the user's font size setting. 1rem is usually 16px, so mb-3 is 16px of space.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Bootstrap's Reboot do with box-sizing?

    With border-box a box that is 240px wide stays 240px wide even with padding and a border, which makes layout math predictable.
  2. 2. Why does text on a page with no container touch the edge of the browser window?

    Reboot sets the body margin to 0. A .container (with padding and a max-width) gives content breathing room and a readable line length.
  3. 3. What is the purpose of writing <h2 class="h4">?

    Choose heading elements for document structure and use the h1 to h6 classes for visual size, so outline and appearance stay independent.
  4. 4. Why do utility classes like mb-3 use !important?

    A utility should do exactly what its name says, wherever it is used. !important guarantees it wins over the component's own rules.

Summary

  • Reboot gives every browser the same starting point: border-box sizing, a system font, no body margin and consistent spacing.
  • A container centers content and restores side padding.
  • Class names are labels for CSS rules; many use --bs-* variables.
  • Compose small utility and component classes instead of writing new CSS.
  • Use heading classes (h1 to h6) when the look and the semantic level differ.

Next: Containers.