#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Bootstrap Fundamentals

Bootstrap Grids

The Bootstrap grid is a system of rows and columns, built on flexbox, that lets you lay out a page in up to twelve columns and change that layout at different screen widths. You use it whenever content should sit side by side on larger screens but stack neatly on phones.

Containers, rows and columns

Every grid follows the same nesting order:

  1. A .container (fixed max width per breakpoint) or .container-fluid (full width) sets the outer bounds and side padding.
  2. A .row is a flex container that holds columns and offsets their padding with negative margins.
  3. Columns, such as .col or .col-md-6, are the only direct children of a row and hold your actual content.

Skipping the row and putting columns straight into a container breaks the spacing, because the gutters are designed around that row-column pairing.

Reading the column classes

A class like col-md-4 has three parts: col, a breakpoint (md), and a span out of twelve (4). It means "from the medium breakpoint upward, take four of twelve columns". Below that breakpoint the column falls back to full width.

InfixApplies from width
(none)0 and up
sm576px
md768px
lg992px
xl1200px
xxl1400px

Bootstrap is mobile first, so a breakpoint class affects that size and everything larger. You combine classes to describe several layouts at once.

<div class="container">
  <div class="row g-3">
    <div class="col-12 col-md-6 col-lg-4">Card one</div>
    <div class="col-12 col-md-6 col-lg-4">Card two</div>
    <div class="col-12 col-md-12 col-lg-4">Card three</div>
  </div>
</div>

On a phone, each card takes the full width. From 768px, the first two sit side by side and the third fills the next line. From 992px, all three share one line.

Auto-width columns and gutters

Plain .col without a number divides the row equally, so three .col elements each take a third. .col-auto sizes a column to its content. You can mix them: a fixed .col-3 sidebar next to a .col that absorbs the remaining space.

Gutters are the gaps between columns. In Bootstrap 5 you control them on the row with g-* (both directions), gx-* (horizontal) and gy-* (vertical), from 0 to 5. The row-cols-* classes, such as row-cols-md-3, set how many columns appear per line without adding a class to each child.

Common grid mistakes

  • Spans adding to more than twelve. Columns that total more than twelve in one row wrap onto a new line. Sometimes that is what you want, but often it is an accident.
  • Styling columns directly. Adding borders or backgrounds to the column element makes the padding look uneven. Put a card or inner div inside the column and style that.
  • Using old classes. Bootstrap 4 helpers like no-gutters and the -xs- infix do not exist in Bootstrap 5. Use g-0 and the infix-free col-* instead.

Nesting a grid

You can place a new .row inside a column to split it further. The nested row again counts to twelve, relative to its parent column, not the whole page.

The habit to build: start with the phone layout using col-12 or plain col, then add md and lg classes only where the layout should change.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course