Nesting rows and columns helps you create complex layouts inside a webpage. It lets you organize content in smaller sections inside bigger sections.
Nesting rows and columns in Bootsrap
<div class="row"> <div class="col"> <div class="row"> <div class="col">Nested content</div> </div> </div> </div>
Always put a .row inside a .col when nesting.
Use columns inside the nested row to keep the grid structure.
<div class="row"> <div class="col-6"> <div class="row"> <div class="col-6">Nested 1</div> <div class="col-6">Nested 2</div> </div> </div> <div class="col-6">Main column 2</div> </div>
<div class="row"> <div class="col"> <div class="row"> <div class="col">Nested full width</div> </div> </div> </div>
This page shows a main row with two columns. The first column contains a nested row with two smaller columns inside. Borders and padding help you see the layout clearly.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Nesting Rows and Columns Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <main class="container mt-4"> <h1 class="mb-4">Nesting Rows and Columns</h1> <div class="row border p-3"> <div class="col-8 border p-3"> Main Column 1 <div class="row mt-3"> <div class="col-6 border p-2">Nested Column 1</div> <div class="col-6 border p-2">Nested Column 2</div> </div> </div> <div class="col-4 border p-3">Main Column 2</div> </div> </main> </body> </html>
Use borders or background colors temporarily to see how your nested grid looks.
Remember that nested rows must be inside columns to keep the layout working.
Bootstrap columns add padding (gutter) automatically for spacing.
Nesting rows and columns lets you build detailed layouts inside bigger sections.
Always put a .row inside a .col when nesting.
Use borders or colors to check your layout visually while building.
Practice
Solution
Step 1: Understand Bootstrap grid nesting rules
Bootstrap requires that a.rowmust be inside a.containeror.colfor proper alignment.Step 2: Identify correct nesting for rows and columns
When nesting, a.rowshould be placed inside a.colto maintain the grid structure and spacing.Final Answer:
Place a.rowinside a.colelement -> Option AQuick Check:
Nesting rows inside columns = Place a.rowinside a.colelement [OK]
.row inside .col for layout [OK]- Putting
.rowdirectly inside another.row - Placing
.coldirectly inside.containerwithout a row - Nesting
.containerinside.row
Solution
Step 1: Check the outer container
The outermost element should be a.colto allow nesting inside it.Step 2: Verify the nested structure
Inside the.col, a.rowis correctly nested, and inside that row, columns can be placed.Final Answer:
<div class='col'><div class='row'><div class='col'></div></div></div> -> Option AQuick Check:
Row inside col, then col inside row =<div class='col'><div class='row'><div class='col'></div></div></div>
[OK]
.row inside .col, then add .col inside row [OK]- Starting with
.rowinstead of.colfor nesting - Nesting
.rowdirectly inside another.row - Using
.colinside.colwithout a row
<div class='container'>
<div class='row'>
<div class='col-6'>Left</div>
<div class='col-6'>
<div class='row'>
<div class='col-6'>Top Right</div>
<div class='col-6'>Bottom Right</div>
</div>
</div>
</div>
</div>Solution
Step 1: Analyze the outer row columns
The outer row has two columns each withcol-6, so they split the container horizontally 50% each.Step 2: Analyze the nested row inside the right column
The right column contains a nested row with twocol-6columns, which split that right half horizontally into two equal parts side by side.Final Answer:
Left column takes half width; right column splits into two equal columns side by side horizontally -> Option CQuick Check:
Nested row splits right col horizontally = Left column takes half width; right column splits into two equal columns side by side horizontally [OK]
- Thinking nested columns stack vertically by default
- Assuming nested row splits full container width
- Confusing col-6 with full width
<div class='container'>
<div class='row'>
<div class='row'>
<div class='col'>Nested Column</div>
</div>
</div>
</div>Solution
Step 1: Check nesting rules for rows and columns
Bootstrap requires that a.rowmust be inside a.colwhen nested.Step 2: Identify the incorrect nesting
The code nests a.rowdirectly inside another.rowwithout wrapping it in a.col, which breaks the grid structure.Final Answer:
A.rowis nested directly inside another.rowwithout a.col-> Option BQuick Check:
Row inside row without col = A.rowis nested directly inside another.rowwithout a.col[OK]
.row directly inside another .row [OK]- Nesting rows without columns
- Assuming
.colis optional inside rows - Confusing container placement
Solution
Step 1: Understand the layout goal
The left half should have two stacked sections, so inside the leftcol-6, we need a nested row with two full-width columns stacked vertically.Step 2: Check the nesting structure
<div class='row'> <div class='col-6'> <div class='row'> <div class='col-12'>Top Left</div> <div class='col-12'>Bottom Left</div> </div> </div> <div class='col-6'>Right Side</div> </div>nests a.rowinside the left.col-6and uses two.col-12columns stacked vertically, which is correct. The right.col-6is a single section.Final Answer:
<div class='row'><div class='col-6'><div class='row'><div class='col-12'>Top Left</div><div class='col-12'>Bottom Left</div></div></div><div class='col-6'>Right Side</div></div> -> Option DQuick Check:
Nested row with stacked full-width cols inside left half =<div class='row'> <div class='col-6'> <div class='row'> <div class='col-12'>Top Left</div> <div class='col-12'>Bottom Left</div> </div> </div> <div class='col-6'>Right Side</div> </div>[OK]
- Placing columns directly inside columns without a row
- Using wrong column widths for stacking
- Missing nested row inside the left column
Ready to prove it?
Pass the test and this pattern moves unknown
