Containers are the most fundamental layout element in Bootstrap. They are required to wrap, pad, and visually center the content on your website. Without a container, your content will touch the very edges of the browser window.
In Bootstrap, a container serves three major purposes:
Bootstrap provides three main types of containers. Depending on the class you use, the container will behave differently as the screen size changes.
.container)The standard .container class provides a responsive, fixed-width layout. As you resize the browser, this container snaps to specific maximum widths (breakpoints) so the layout stays neat and readable.
<!-- Example of a fixed container -->
<div class="container">
<h1>Welcome to my Website</h1>
<p>This content is nicely centered and padded.</p>
</div>
.container-fluid)The .container-fluid class gives you a full-width container. No matter how large the screen gets, the container will always stretch to fill 100% of the screen width, while still maintaining a small amount of padding on the sides.
<!-- Example of a fluid container -->
<div class="container-fluid">
<h1>Full Width Section</h1>
<p>Great for headers, footers, or edge-to-edge image banners.</p>
</div>
.container-{breakpoint})Bootstrap 5 introduced responsive containers. These allow you to specify an exact screen size where the container should stop being 100% wide and start acting like a standard fixed container.
For example, if you use .container-md, the container will be 100% wide on mobile devices, but as soon as the screen hits the "Medium" breakpoint (768px), it will switch to a fixed, centered max-width.
<div class="container-md">
<p>100% wide on small screens. Fixed width on medium and larger screens.</p>
</div>
This table shows exactly how wide each container gets at every screen size. Pay close attention to when the width is 100% versus when it snaps to a fixed pixel width.
| Class | Extra small <576px |
Small (sm) ≥576px |
Medium (md) ≥768px |
Large (lg) ≥992px |
X-Large (xl) ≥1200px |
XX-Large (xxl) ≥1400px |
|---|---|---|---|---|---|---|
.container |
100% | 540px | 720px | 960px | 1140px | 1320px |
.container-sm |
100% | 540px | 720px | 960px | 1140px | 1320px |
.container-md |
100% | 100% | 720px | 960px | 1140px | 1320px |
.container-lg |
100% | 100% | 100% | 960px | 1140px | 1320px |
.container-xl |
100% | 100% | 100% | 100% | 1140px | 1320px |
.container-xxl |
100% | 100% | 100% | 100% | 100% | 1320px |
.container-fluid |
100% | 100% | 100% | 100% | 100% | 100% |
By default, containers only have horizontal padding (left and right) so the text doesn't hit the screen edges. They do not have top or bottom padding.
To add vertical spacing, you can use Bootstrap's built-in spacing utility classes (like pt-5 for padding-top, or my-4 for margin-y-axis).
<!-- Container with extra top and bottom padding -->
<div class="container pt-5 pb-5">
<h2>Spaced out content</h2>
</div>
<div>, and then put a .container inside it to keep the text centered!