Lesson 2: Containers

One of the things - if not the MAIN thing - that makes Bootstrap so great is its grid system. This 12 column grid is flexible enough for any layout you can possibly require, easy to learn, and even easier to use.

Containers are the most basic layout element in Bootstrap and are required when using the default grid system. Containers are used to contain, pad, and (sometimes) center the content within them. While containers can be nested, most layouts do not require a nested container.

Bootstrap comes with three different containers:

1200px for reference. Most Bootstrap items contain a gutter on the left and right.

The standard container

The basic container in Bootstrap displays at the max width breakpoint by default and changes width when each smaller breakpoint is reached. Resize the width of your browser window to see the breakpoints change.

Note: Containers are not visible! These lessons and examples have styles applied so you can see how they work.

This is a standard container. It stays the max breakpoint (1200px) in width until the viewport drops below that.
<div class="container">
  <!-- Content here -->
</div>

 

The fluid container

The fluid container in Bootstrap displays at 100% of the viewport width always. Resize the width of your browser window to see the container stays edge-to-edge.

This is a fluid container. It spans the whole viewport.
<div class="container-fluid">
  ...
</div>

 

Responsive containers

Responsive containers in Bootstrap display at the max width breakpoint by default and change width when each specified breakpoint is reached. Resize the width of your browser window to see the breakpoints change. To designate responsive elements in bootstrap you use the abbreviations xl, lg, md, and sm.

1200 wide until small breakpoint (576px)
1200 wide until medium breakpoint (768px)
1200 wide until large breakpoint (992px)
1200 wide until extra large breakpoint (1200px)
<div class="container-sm">100% wide until small breakpoint</div>
<div class="container-md">100% wide until medium breakpoint</div>
<div class="container-lg">100% wide until large breakpoint</div>
<div class="container-xl">100% wide until extra large breakpoint</div>