BBS5 Containers

Learn about Bootstrap 5 containers.

BS5 Containers

Containers are the most basic layout element in Bootstrap and are required when using the default grid system.

Containers are used to wrap content, pad it, and (sometimes) center it within the viewport.

Container Types

Bootstrap 5 offers two main container classes:

  • .container - The class provides a responsive fixed width container
  • .container-fluid - The class provides a full width container, spanning the entire width of the viewport

There are also responsive containers like .container-sm, .container-md, etc., which allow you to specify a class that is 100% wide until the specified breakpoint is reached.

Examples

Fixed Container

html/css

A responsive fixed width container.

<div class="container">
  <h1>My First Bootstrap Page</h1>
  <p>This is some text.</p>
</div>

Fluid Container

html/css

A full width container.

<div class="container-fluid">
  <h1>My First Bootstrap Page</h1>
  <p>This is some text.</p>
</div>

Container Border and Color

html/css

Using utilities to style a container.

<div class="container p-5 my-5 border bg-dark text-white">
  <h1>My First Bootstrap Page</h1>
  <p>This container has a dark background and white text.</p>
</div>

Responsive Container

html/css

Different responsive container sizes.

<div class="container-sm border">.container-sm</div>
<div class="container-md border">.container-md</div>
<div class="container-lg border">.container-lg</div>
<div class="container-xl border">.container-xl</div>

Test Your Knowledge

1. Which class provides a responsive fixed width container?

2. Which class provides a full width container?