0
0
Bootsrapmarkup~8 mins

Nesting rows and columns in Bootsrap - Performance & Optimization

Choose your learning style9 modes available
Performance: Nesting rows and columns
MEDIUM IMPACT
Nesting rows and columns affects the DOM size and layout calculation time, impacting page rendering speed and visual stability.
Creating a grid layout with nested rows and columns
Bootsrap
<div class="row">
  <div class="col">
    Content
  </div>
  <div class="col">
    Additional Content
  </div>
</div>
Simplifies DOM structure by reducing nesting, minimizing layout recalculations and improving visual stability.
๐Ÿ“ˆ Performance GainSingle reflow and paint, reducing layout thrashing and CLS
Creating a grid layout with nested rows and columns
Bootsrap
<div class="row">
  <div class="col">
    <div class="row">
      <div class="col">
        Content
      </div>
    </div>
  </div>
</div>
Excessive nesting creates many DOM nodes and triggers multiple layout recalculations, increasing rendering time and causing layout shifts.
๐Ÿ“‰ Performance CostTriggers multiple reflows and repaints due to nested layout recalculations
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Deeply nested rows and columnsHigh (many nested divs)Multiple reflows per nested levelHigh paint cost due to layout thrashing[X] Bad
Flat row with multiple columnsLow (few divs)Single reflowLow paint cost[OK] Good
Rendering Pipeline
Nesting rows and columns increases the number of DOM nodes and complexity of CSS calculations. The browser must calculate styles and layouts for each nested element, causing more layout and paint operations.
โ†’Style Calculation
โ†’Layout
โ†’Paint
โš ๏ธ BottleneckLayout stage is most expensive due to recalculations triggered by nested grid containers.
Core Web Vital Affected
CLS
Nesting rows and columns affects the DOM size and layout calculation time, impacting page rendering speed and visual stability.
Optimization Tips
1Avoid deep nesting of rows and columns to reduce DOM complexity.
2Flatten grid layouts to minimize layout recalculations and improve CLS.
3Use Bootstrapโ€™s grid system as intended with minimal nesting for best performance.
Performance Quiz - 3 Questions
Test your performance knowledge
How does deeply nesting rows and columns in Bootstrap affect page performance?
AIt has no impact on rendering performance.
BIt increases layout recalculations causing slower rendering.
CIt reduces the number of DOM nodes improving speed.
DIt decreases paint cost by simplifying styles.
DevTools: Performance
How to check: Record a performance profile while loading the page. Look for long layout and paint tasks caused by nested grid elements.
What to look for: High layout duration and multiple layout recalculations indicate costly nested rows and columns.