Bootstrap 5 Grid System 🎯

beginner
16 min

Bootstrap 5 Grid System 🎯

Welcome to our comprehensive guide on Bootstrap 5 Grid System! In this lesson, we'll dive deep into understanding the powerful grid system that Bootstrap 5 offers, making web design faster and easier than ever. Let's get started!

What is Bootstrap 5 Grid System? 📝

Bootstrap 5 Grid System is a powerful tool for designing responsive websites. It allows us to create flexible and adaptive layouts that adjust to various screen sizes. With the grid system, we can organize content, control layout, and ensure our websites look great on all devices.

Why use Bootstrap 5 Grid System? 💡

  • Responsive Design: The grid system ensures our websites look great on all devices, from desktops to mobile phones.
  • Efficiency: It saves time by providing pre-built components and layouts.
  • Flexibility: We can easily adjust the layout to fit our content needs.

Bootstrap 5 Grid Basics 💡

Container

A container is the parent element for all grid items. It sets the maximum width and ensures horizontal centering.

html
<div class="container"> <!-- Grid content here --> </div>

Rows and Columns

Rows divide the container into vertical spaces, while columns create horizontal spaces for content.

html
<div class="row"> <div class="col">Content</div> <div class="col">Content</div> <div class="col">Content</div> </div>

Grid System Classes

Grid Columns

Bootstrap 5 offers 12 columns in a grid. You can control the number of columns by using the col-* classes.

html
<div class="row"> <div class="col-6">Column 1</div> <div class="col-6">Column 2</div> </div>

Grid Breakpoints

Bootstrap 5 has several breakpoints to handle different screen sizes. The classes for each breakpoint start with col-.

html
<!-- For extra small devices (phones, 576px and up) --> <div class="col-xs">Column</div> <!-- For small devices (tablets, 768px and up) --> <div class="col-sm">Column</div> <!-- For medium devices (desktops, 992px and up) --> <div class="col-md">Column</div> <!-- For large devices (large desktops, 1200px and up) --> <div class="col-lg">Column</div> <!-- For extra large devices (large desktops, 1400px and up) --> <div class="col-xl">Column</div>

Grid System Examples

Example 1: Basic Grid Layout

html
<div class="container"> <div class="row"> <div class="col-6">Column 1</div> <div class="col-6">Column 2</div> </div> <div class="row"> <div class="col-4">Column 1</div> <div class="col-4">Column 2</div> <div class="col-4">Column 3</div> </div> </div>

Example 2: Nested Grid Layout

html
<div class="container"> <div class="row"> <div class="col-6"> <div class="row"> <div class="col-4">Nested Column 1</div> <div class="col-4">Nested Column 2</div> <div class="col-4">Nested Column 3</div> </div> </div> <div class="col-6">Nested Column 4</div> </div> </div>

Quiz

Quick Quiz
Question 1 of 1

What is the parent element for all grid items in Bootstrap 5?

By now, you should have a good understanding of the Bootstrap 5 Grid System. In the next lesson, we'll explore more advanced features and techniques. Happy coding! 🚀