Holy Grail Three-column Layout
Header, nav, main, aside and footer in CSS grid areas that collapse to one column when the width shrinks.
AI prompt
Clean wireframe diagram of a web page layout with five labelled regions in a light neutral palette: a header bar across the top, a left navigation column, a wide main content area, a right aside column and a footer bar across the bottom, drawn with thin outlines and soft grey fills; beside it a narrow phone-width version with the regions stacked in the order header, main, navigation, aside, footer. Negative: gradients, shadows, clutter, text errors. Reduced motion: static diagram.About this pattern
Definition
The holy grail layout has a header, a footer and three columns between them: navigation, main content and an aside. With CSS grid areas it needs no hacks, the main content can come first in the HTML for accessibility, and the layout can collapse to a single column when space runs out.
When to use it
- grid-template-areas names the regions; the middle column uses minmax so main grows and the sides stay fixed.
- Put main first in the source so keyboard and screen reader users reach it early.
- At narrow widths switch to one column: header, main, nav, aside, footer.
- Container queries let the layout respond to its own width, not the window.
What the controls do
- A width slider resizes the frame; the layout switches at about 320px.
Motion & timing
- The layout changes instantly as the width changes.
- Reduced motion: no animation is involved.
Tips & variations
- Use landmarks: header, nav, main, aside, footer.
- Do not let the aside push essential content below a very long list.
Code of this live preview
<div class="bx"><div class="fw" id="fw"><div class="pg"><header>Header</header><main>Main content</main><nav>Nav</nav><aside>Aside</aside><footer>Footer</footer></div></div><label class="rw">Width <b id="wv">380px</b><input id="ws" type="range" min="200" max="380" value="380"></label><p class="out" id="out"></p></div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.fw{container-type:inline-size;box-sizing:border-box;margin:0 auto;border:1px dashed #c9c9c4;border-radius:10px;padding:6px;max-width:100%}.pg{display:grid;gap:5px;grid-template-columns:70px minmax(0,1fr) 70px;grid-template-areas:"h h h" "n m a" "f f f";font-size:11px;text-align:center}.pg>*{border-radius:6px;padding:8px 4px;display:grid;place-items:center}header{grid-area:h;background:#dfe6f3}nav{grid-area:n;background:#f1e3cc}main{grid-area:m;background:#fff;border:1px solid var(--line);min-height:84px}aside{grid-area:a;background:#e0f0e3}footer{grid-area:f;background:#e9e9e6}@container (max-width:320px){.pg{grid-template-columns:minmax(0,1fr);grid-template-areas:"h" "m" "n" "a" "f"}main{min-height:48px}}.out{font-size:12px;color:var(--muted)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}const ws=document.getElementById('ws'),fw=document.getElementById('fw'),out=document.getElementById('out');
function up(){const w=+ws.value;fw.style.width=w+'px';document.getElementById('wv').textContent=w+'px';out.textContent=w<=320?'Narrow: one column, main comes before nav and aside.':'Wide: nav, main and aside sit side by side.';}
ws.addEventListener('input',up);up();One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Holy Grail Three-column Layout — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}a{color:inherit;text-decoration:none}ul,ol,p,h4{margin:0;padding:0}.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.pre{display:flex;gap:5px;flex-wrap:wrap}.pre button{height:28px;padding:0 11px;border-radius:99px;border:1px solid var(--line);background:var(--surface);font-size:11px;cursor:pointer}
.pre button[aria-pressed=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.bx{width:min(330px,100%);display:grid;gap:9px}.rw{display:grid;gap:3px;font-size:11.5px;color:var(--muted)}.rw b{color:var(--text);font-weight:600}input[type=range]{width:100%;accent-color:#171717}
.out{font-size:12px;color:var(--muted);line-height:1.4}.out b{color:var(--text)}
button:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.fw{container-type:inline-size;box-sizing:border-box;margin:0 auto;border:1px dashed #c9c9c4;border-radius:10px;padding:6px;max-width:100%}.pg{display:grid;gap:5px;grid-template-columns:70px minmax(0,1fr) 70px;grid-template-areas:"h h h" "n m a" "f f f";font-size:11px;text-align:center}.pg>*{border-radius:6px;padding:8px 4px;display:grid;place-items:center}header{grid-area:h;background:#dfe6f3}nav{grid-area:n;background:#f1e3cc}main{grid-area:m;background:#fff;border:1px solid var(--line);min-height:84px}aside{grid-area:a;background:#e0f0e3}footer{grid-area:f;background:#e9e9e6}@container (max-width:320px){.pg{grid-template-columns:minmax(0,1fr);grid-template-areas:"h" "m" "n" "a" "f"}main{min-height:48px}}.out{font-size:12px;color:var(--muted)}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
</style></head>
<body><div class="stage">
<div class="bx"><div class="fw" id="fw"><div class="pg"><header>Header</header><main>Main content</main><nav>Nav</nav><aside>Aside</aside><footer>Footer</footer></div></div><label class="rw">Width <b id="wv">380px</b><input id="ws" type="range" min="200" max="380" value="380"></label><p class="out" id="out"></p></div>
</div>
<script>
const ws=document.getElementById('ws'),fw=document.getElementById('fw'),out=document.getElementById('out');
function up(){const w=+ws.value;fw.style.width=w+'px';document.getElementById('wv').textContent=w+'px';out.textContent=w<=320?'Narrow: one column, main comes before nav and aside.':'Wide: nav, main and aside sit side by side.';}
ws.addEventListener('input',up);up();
</script>
</body></html>