Master Bootstrap From Scratch

Clear, interactive, and structured Bootstrap lessons designed for beginners and developers.

Bootstrap Containers

Learn how Bootstrap containers organize and control the width of content on a web page.

A container is one of the most important layout classes in Bootstrap. It provides proper horizontal spacing and keeps the content organized and readable on different screen sizes.

What is a Bootstrap Container?

A Bootstrap container is a wrapper element used to hold the main content of a web page.

Bootstrap automatically manages the container's width according to the screen size. This makes it easier to create responsive layouts.

Simple Explanation:

Think of a container as a box that keeps your website content properly aligned instead of allowing the content to spread across the entire screen.

How a Container Works

Browser Screen
Bootstrap Container
Content
Content
Content

Types of Bootstrap Containers

Bootstrap provides different container classes for different layout requirements.

Class Purpose
.container Creates a responsive fixed-width container.
.container-fluid Creates a container that uses the full available width.
.container-sm Responsive container starting from the small breakpoint.
.container-md Responsive container starting from the medium breakpoint.
.container-lg Responsive container starting from the large breakpoint.
.container-xl Responsive container starting from the extra-large breakpoint.
.container-xxl Responsive container starting from the extra-extra-large breakpoint.

1. .container

The .container class creates a responsive fixed-width container. Its maximum width changes at Bootstrap's responsive breakpoints.

<div class="container">

    <h2>CIIT Training Institute</h2>

    <p>
        Learn Bootstrap with practical examples.
    </p>

</div>

Example Output

CIIT Training Institute

Learn Bootstrap with practical examples.

2. .container-fluid

The .container-fluid class creates a container that takes the full available width of the screen.

<div class="container-fluid">

    <h2>Full Width Content</h2>

    <p>
        This container uses the complete available width.
    </p>

</div>

Example

Full Width Section

This section can use the available width of the screen.

Responsive Containers

Bootstrap also provides responsive container classes. These containers change their maximum width according to the selected breakpoint.

<div class="container-md">

    <h2>
        Responsive Bootstrap Container
    </h2>

</div>
Remember:

Responsive containers are useful when you want different layout behavior at different screen sizes.

Container with Row and Columns

Containers are commonly used together with Bootstrap's grid system. A typical structure is:

<div class="container">

    <div class="row">

        <div class="col-md-6">
            Left Content
        </div>

        <div class="col-md-6">
            Right Content
        </div>

    </div>

</div>

Structure

Container
Column 1
Column 2

Real-Life Example

Think About a Classroom

Imagine a CIIT Training Institute classroom. The classroom walls define the available space, while desks are arranged neatly inside that space.

Similarly, a Bootstrap container defines the usable content area of a webpage and helps keep the content properly aligned.

.container vs .container-fluid

Feature .container .container-fluid
Width Responsive maximum width Full available width
Responsive Yes Yes
Common Usage Main page content Full-width sections

Common Mistakes

  • Forgetting to include Bootstrap CSS.
  • Using unnecessary nested containers.
  • Confusing .container with .container-fluid.
  • Not using the container properly with rows and columns.

Summary

In this lesson, we learned that Bootstrap containers are used to organize and control the width of webpage content.

We learned about .container, .container-fluid and responsive container classes.

We also learned how containers work together with rows and columns to create responsive layouts.