Bs5 Containers in Bootstrap
In Bootstrap 5 (BS5), containers are layout wrappers used to align and pad your content. They are the foundation of the Bootstrap grid system, ensuring proper alignment and spacing within your layout.
? Types of Containers
1. .container
Fixed-width container
Responsive at each breakpoint.
<div class="container"> <p>This is a responsive fixed-width container.</p></div>2. .container-fluid
Full-width container
Spans the entire width of the viewport at all breakpoints.
<div class="container-fluid"> <p>This is a full-width container.</p></div>3. .container-{breakpoint}
Responsive containers that become fixed-width at specified breakpoints.
| Class | Becomes fixed-width at ? |
|---|---|
.container-sm | Small (576px) |
.container-md | Medium (768px) |
.container-lg | Large (992px) |
.container-xl | Extra Large (1200px) |
.container-xxl | Extra Extra Large (1400px) |
<div class="container-md"> <p>This is full-width until ?768px, then fixed-width.</p></div>? How Containers Work with Grid
<div class="container"> <div class="row"> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> <div class="col"> One of three columns </div> </div></div>Always wrap
.rowand.col-*inside a.container,.container-fluid, or.container-{breakpoint}.
? Best Practices
Use
.containerfor most pages.Use
.container-fluidfor full-width layouts or background sections.Use
.container-{breakpoint}for layout control in responsive designs.
Would you like examples on nesting containers, containers in navbars, or using containers with utility spacing classes?