Performance: Why complex layouts need patterns
HIGH IMPACT
This affects how fast the page loads and how smoothly the layout appears when resizing or interacting.
<div class="grid grid-rows-layout grid-cols-layout gap-4"> <header class="row-span-1 col-span-full">Header</header> <nav class="row-span-1 col-span-1">Sidebar</nav> <main class="row-span-2 col-span-3">Main content</main> <footer class="row-span-1 col-span-full">Footer</footer> </div> <style> @layer utilities { .grid-rows-layout { grid-template-rows: auto 1fr auto; } .grid-cols-layout { grid-template-columns: 200px 1fr 1fr; } } </style>
<div class="flex flex-col"> <div class="flex flex-row"> <div class="w-1/3">Item 1</div> <div class="w-1/3">Item 2</div> <div class="w-1/3">Item 3</div> </div> <div class="grid grid-cols-4 gap-4"> <div>Grid Item 1</div> <div>Grid Item 2</div> <div>Grid Item 3</div> <div>Grid Item 4</div> </div> <div class="absolute top-0 left-0">Overlay</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mixed flex, grid, absolute | High (many nested nodes) | Multiple reflows on resize | High paint cost due to layout thrashing | [X] Bad |
| Single CSS Grid pattern | Moderate (flat structure) | Single reflow on resize | Lower paint cost, smoother rendering | [OK] Good |