1. What is Bootstrap 5 Grid System
The grid system in Bootstrap 5 is based on 12-column layout. Each row in a grid is divided into 12 equal parts. You can specify how many columns a particular element should span in different screen sizes.
Key Concepts
- Containers: Used to wrap the content and align in a grid system.
- Rows: Rows are horizontal group of columns.
- Columns: Columns are the building blocks of the grid where you place your content.
2. Basic Grid Structure
Below is a basic example showing the basic grid structure:-
Output

The above example contains the following classes for the grid system:-
.container
: for responsive and fixed width layout..row
: creates horizontal row to align columns..col
: Divides the row into equal width columns.
3. Grid Breakpoints
In Bootstrap 5, you will get 6 responsive breakpoints for grid layouts:
Breakpoint Name | Class Prefix | Min Width (px) |
---|---|---|
Extra Small |
col
|
<576px
|
Small |
col-sm
|
≥576px
|
Medium |
col-md
|
≥768px
|
Large |
col-lg
|
≥992px
|
Extra Large |
col-xl
|
≥1200px
|
Extra Extra Large |
col-xxl
|
≥1400px
|
Example with breakpoints:
Output

Explanation:
col-sm-6
: Span 6 grid columns on small screens (50% width)col-md-4
: Span 4 grid columns on medium screens (33.3% width)col-sm-12
: Span 12 grid columns on small screens (100% width)
4. Equal and Variable Column Widths
Equal-Width Columns
Output

Columns automatically divide the available space equally.
Variable Width Columns
Output

Use col-[number]
to specify how many columns a specific element spans.
5. Nesting Grid Columns
You can create nested grids by placing rows and columns inside a column:
Output

6. Gutter Control
Gutters are the spaces between columns. In Bootstrap 5, you can control gutter spacing using classes.
Output

Explanation
g-3
: Adds a gutter of1rem
between columns and rows.- Other gutter sizes are:
g-0
,g-1
,g-2
,…,g-5
.
7. Responsive Order Classes
You can easily change the order of columns according to different screen sizes.
Output

8. Hiding and Showing Columns
Use the .d-none
and display utility classes to hide and show columns on specific screen sizes.
Output

9. Responsive Layout Using Grid System
Here’s a complete layout using the grid system:-
Output

After learning the complete grid system, you can easily create dynamic and responsive layout for any type of web page.