Bootstrap 5·Bootstrap from grid to dashboard

Containers and spacing

Control width and rhythm with containers and the spacing scale.

Beginner 11 min read Lesson 2 of 300 Challenge included
What you will be able to do
  • Use container for centred max-width layouts.
  • Use container-fluid for full-width layouts.
  • Use py-5 for section rhythm and gap-3 for component spacing.
  • Use mt-auto to push a footer to the bottom of a flex column.

In plain English

Bootstrap spacing utilities follow a predictable scale from 0 to 5. The m and p prefixes set margin and padding, and side suffixes target top, bottom, start and end. Consistent spacing is most of what makes an interface look designed.

spacing.htmlHTML
<div class="container py-5">
  <section class="mb-4">
    <h1 class="mb-2">Course</h1>
    <p class="mb-0 text-body-secondary">Short description.</p>
  </section>
</div>
Your turn

Give a card breathing room

Easy

Add 4 units of padding all around a card using Bootstrap utilities.

HTML · starter
<div class="card">
Check your understanding before moving on.
Knowledge checkQuestion 1

Which class adds vertical padding on both top and bottom?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Typography and tables
Lesson 2 of 300 · 0% of course