Bootstrap 5 Grid System with Examples

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:-

Test it Live

Output

Basic Grid Structure

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:

Test it Live

Output

Basic Grid Structure

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

Test it Live

Output

Equal-Width Columns

Columns automatically divide the available space equally.

Variable Width Columns

Test it Live

Output

Variable-Width Columns

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:

Test it Live

Output

Nesting Grid Columns

6. Gutter Control

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

Test it Live

Output

Gutter Control

Explanation

  • g-3: Adds a gutter of 1rem 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.

Test it Live

Output

Responsive Order Classes

8. Hiding and Showing Columns

Use the .d-none and display utility classes to hide and show columns on specific screen sizes.

Test it Live

Output

Hiding and Showing Columns

9. Responsive Layout Using Grid System

Here’s a complete layout using the grid system:-

Test it Live

Output

Responsive Layout Using Grid System

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

Complete Example of Grid System

Test it Live

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.