Chapter-2: Containers in Bootstrap
In Bootstrap, containers are the most basic layout element. Think of them as the box that holds your website content. They add proper padding and alignment so your text and images do not stick to the edges of the browser window. They also help structure your layout so everything stays responsive and looks consistent across different screen sizes.
Here is the breakdown of the three types you asked about.
1. .container (The “Fixed-Width” Box)
This is the most common choice. It creates a responsive, fixed-width box that changes its size based on the screen width (breakpoints).
- How it works: It stays centered and leaves “white space” (gutters) on the left and right sides of the page on larger screens.
- Best for: Standard websites (like blogs or news sites) where you want a clean, centered look.
2. .container-fluid (The “Full-Width” Box)
This container is much simpler: it is always 100% wide, no matter the device size.
- How it works: It stretches to the very edges of the browser window (minus a tiny bit of side padding).
- Best for: Dashboards, map-based apps, or any design where you want to utilize every inch of screen real estate.
3. .container-{breakpoint} (The “Hybrid”)
This is a “fluid-until-fixed” container. It stays 100% wide until it hits a specific screen size, then it starts behaving like a regular fixed container.
- Example:
.container-md:- On Small screens (phones): It is 100% wide (fluid).
- On Medium and larger screens (tablets/laptops): It becomes fixed-width (centered with margins).
- Best for: When you want a full-width mobile experience but a centered desktop experience.
Comparison Table
| Class | Extra Small (<576px) | Medium (≥768px) | Extra Large (≥1200px) |
.container | 100% | 720px | 1140px |
.container-fluid | 100% | 100% | 100% |
.container-md | 100% | 720px | 1140px |
Code Example of containers
Copy this into your HTML to see the difference in action:
HTML
<div class="container" style="background: lightblue;">
I am a standard container.
</div>
<div class="container-fluid" style="background: lightgreen;">
I am always full-width.
</div>
<div class="container-lg" style="background: lightcoral;">
I am fluid until the 'Large' breakpoint!
</div>
Quick Tip: Never nest a container inside another container. It creates messy, unpredictable padding! Stick to one container per section or one for the entire page.
Advanced Tip: Responsive Gutters
Containers don’t just control width; they also control gutters (the padding between columns).
By default, containers have horizontal padding. If you ever find your content is touching the very edge of the screen and it looks “unprofessional,” it’s usually because you accidentally removed the container or used a
rowwithout a container wrapper.Rule of Thumb: >
Container→Row→ColumnNever skip a step in this hierarchy if you want your alignment to stay perfect.
Check out our resources!
- Bootstrap Templates: Explore our Bootstrap Projects section.
- Free E-Books: Download your Free E-Books here.


