Performance: Holy grail layout
This affects page load speed and rendering performance by how the layout is structured and how CSS Grid or Flexbox is used to arrange main content and sidebars.
<div class="grid grid-rows-[auto_1fr_auto] grid-cols-[200px_1fr_200px] min-h-screen"> <header class="row-start-1 col-span-3">Header</header> <aside class="row-start-2 col-start-1">Left Sidebar</aside> <main class="row-start-2 col-start-2">Main Content</main> <aside class="row-start-2 col-start-3">Right Sidebar</aside> <footer class="row-start-3 col-span-3">Footer</footer> </div>
<div class="container"> <div class="header">Header</div> <div class="sidebar-left" style="float:left; width: 200px;">Left Sidebar</div> <div class="content" style="margin-left: 200px; margin-right: 200px;">Main Content</div> <div class="sidebar-right" style="float:right; width: 200px;">Right Sidebar</div> <div class="footer">Footer</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Float-based holy grail layout | Moderate (due to extra wrappers for clearing floats) | Multiple reflows on load and resize | Higher paint cost due to layout thrashing | [X] Bad |
| CSS Grid holy grail layout with Tailwind | Minimal extra DOM nodes | Single reflow on load | Lower paint cost with stable layout | [OK] Good |
flex flex-row.grid grid-cols-3 uses grid, not flex. Options C and D use flex-col which stacks vertically, not horizontally.<div class="flex flex-row h-screen"> <aside class="w-48 bg-gray-200">Left</aside> <main class="flex-grow bg-white">Center</main> <aside class="w-48 bg-gray-200">Right</aside> </div>
flex-grow, so it expands to fill leftover space between sidebars.<div class="flex flex-col h-screen">
<header class="h-16 bg-blue-500">Header</header>
<div class="flex flex-col flex-grow">
<aside class="w-48 bg-gray-200">Left</aside>
<main class="flex-grow bg-white">Center</main>
<aside class="w-48 bg-gray-200">Right</aside>
</div>
<footer class="h-16 bg-blue-500">Footer</footer>
</div>flex flex-col, stacking children vertically.flex-row is required instead of flex-col.<div class="flex flex-row h-screen"> <aside class="w-48 bg-gray-200">Left</aside> <main class="flex-grow bg-white">Center</main> <aside class="w-48 bg-gray-200">Right</aside> </div>
flex-col by default and switch to flex-row on larger screens with sm:flex-row.w-48 to h-12 or similar with responsive utilities.Pass the test and this pattern moves unknown