Bootstrap

Bootstrap Grid Examples

Bootstrap Grid System Examples – From Basic to Advanced

The Bootstrap Grid System is one of the most powerful features of the framework. It’s flexible, mobile-first, and built on top of CSS Flexbox. Whether you’re a beginner or looking to polish your layout skills, these examples will help you master the grid.


1. Basic 2-Column Layout

html
<div class="container">
<div class="row">
<div class="col-6 bg-primary text-white p-3">Left</div>
<div class="col-6 bg-secondary text-white p-3">Right</div>
</div>
</div>

Result:

  • 50% width each on all screen sizes (col-6 + col-6 = 12)


2. Responsive Columns (col-sm, col-md, col-lg)

html
<div class="container">
<div class="row">
<div class="col-12 col-md-6 bg-success text-white p-3">50% on md and up</div>
<div class="col-12 col-md-6 bg-info text-white p-3">50% on md and up</div>
</div>
</div>

Result:

  • Stacks on mobile

  • Side-by-side on tablets (≥768px)


3. 3 Equal Columns

html
<div class="container">
<div class="row">
<div class="col-4 bg-danger text-white p-3">1/3</div>
<div class="col-4 bg-warning text-dark p-3">1/3</div>
<div class="col-4 bg-info text-white p-3">1/3</div>
</div>
</div>

Result:

  • 3 equal columns across all screen sizes


4. Nested Grid (Grid Inside a Grid)

html
<div class="container">
<div class="row">
<div class="col-6 bg-light p-3">
Parent Column
<div class="row">
<div class="col-6 bg-secondary text-white p-2">Nested 1</div>
<div class="col-6 bg-dark text-white p-2">Nested 2</div>
</div>
</div>
<div class="col-6 bg-success text-white p-3">Sibling Column</div>
</div>
</div>

Result:

  • Demonstrates nesting a .row inside a column


5. Auto Layout Columns

html
<div class="container">
<div class="row">
<div class="col bg-info text-white p-3">Auto</div>
<div class="col bg-success text-white p-3">Auto</div>
<div class="col bg-warning text-dark p-3">Auto</div>
</div>
</div>

Result:

  • Automatically equal-width columns

  • No need to specify numbers like col-4


6. Mixed Widths with Auto Columns

html
<div class="container">
<div class="row">
<div class="col-3 bg-danger text-white p-3">Fixed (25%)</div>
<div class="col bg-light p-3">Flexible</div>
</div>
</div>

Result:

  • First column takes 25%, second takes remaining space


7. Responsive Card Grid Example

html
<div class="container">
<div class="row">
<div class="col-12 col-sm-6 col-lg-4 mb-4">
<div class="card">
<div class="card-body">Card 1</div>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-4 mb-4">
<div class="card">
<div class="card-body">Card 2</div>
</div>
</div>
<div class="col-12 col-sm-6 col-lg-4 mb-4">
<div class="card">
<div class="card-body">Card 3</div>
</div>
</div>
</div>
</div>

Result:

  • Cards stack on small screens

  • Two per row on tablets

  • Three per row on desktops


Tips for Using Bootstrap Grid

  • Use .container or .container-fluid for layout wrapping

  • Always place .col-* inside a .row

  • Columns add up to 12 in each row

  • Use responsive classes (col-sm-*, col-md-*, etc.) for adaptive layouts


Conclusion

Bootstrap’s grid system is powerful, flexible, and easy to learn. These examples cover most of the layouts you’ll need for modern web development. Once you understand the 12-column rule and responsive breakpoints, you’re good to go!

Leave a Reply

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