Turning Learners Into Developers
Codekilla
CODEKILLA
back to course
Lesson 03 / 506%· free preview
Bootstrap 5 Basics3/32

BS5 Containers

Containers wrap page content and apply max-width + horizontal padding. Three flavors: .container, .container-fluid, .container-{breakpoint}.

The three container types
ClassBehavior
.containerCentered, fixed max-width that grows in steps at each breakpoint
.container-fluidFull-width, always 100% of viewport
`.container-{smmd
When to use which
  • .container — most pages. Looks right on phones, tablets, and 1920 px monitors.
  • .container-fluid — full-bleed dashboards, hero sections.
  • .container-md — pages that should be edge-to-edge on phones but locked on tablets/up.
Diagram
W B JS Bootstrap 5 · Breakpoints MOBILE-FIRST · MIN-WIDTH RULES xs < 576 px · phones (portrait) sm ≥ 576 px · phones (landscape) md ≥ 768 px · tablets lg ≥ 992 px · desktops xl / xxl ≥ 1200 / 1400 px · HD // styles cascade UP — design for xs first, layer overrides on bigger screens
Real-life Example

GitHub's homepage uses .container for the marketing copy and .container-fluid for the dashboard once you log in — same site, two strategies.

Important. Wrap your content in .container (or .container-fluid) — most Bootstrap components break visually if you skip it.

Key Takeaways
  • .container — fixed-width, centred, breakpoint-aware
  • .container-fluid — always 100% width
  • .container-{sm|md|lg|xl|xxl} — fluid until that breakpoint, fixed above
Interview Questions

Practice Questions
  1. Wrap a heading in .container — observe centred fixed-width.
  2. Switch to .container-fluid and resize the window — note 100% width.
  3. Use .container-md and resize through breakpoints — note when it locks.
Pro Tips
  • Nest containers — outer .container for the page, inner .container-fluid inside for full-bleed sections.
  • Combine with .px-* utilities to fine-tune horizontal padding.
AI-powered recap

Quick recap quiz?

We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.

Ready to move on?
// example library
Want more hands-on snippets in Bootstrap?
Browse 1 runnable example · across 1 chapter · short, copy-paste-friendly · grouped by topic
Explore examples
// interactive coach
Practice this in the Bootstrap Coach
Live HTML sandbox with an AI mentor (Gemini 3-Flash) — edit markup, get instant feedback.
Open Coach
// feedback.matters()
Did this lesson help you?