# Holy Grail Flexbox

> The holy grail layout with Flexbox: sidebars and content wrap onto their own rows without media queries.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: holy grail, flex-wrap, header, sidebar, no media query
- Live preview: https://copy-css.com/snippets/holy-grail-flexbox
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="hg-flex">
  <header>Header</header>
  <div class="hg-flex-body">
    <nav>Nav</nav>
    <main>Content</main>
    <aside>Aside</aside>
  </div>
  <footer>Footer</footer>
</div>
```

## CSS

```css
.hg-flex {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100vh;
}

.hg-flex-body {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 16px;
}

/* When the row is narrower than 160 + 480 + 160px, items wrap */
.hg-flex-body nav,
.hg-flex-body aside {
  flex: 1 1 160px;
}

.hg-flex-body main {
  flex: 4 1 480px;
}
```

## Notes

- This CSS Holy Grail Flexbox is 23 lines of pure CSS (0.3 KB) with no JavaScript and no dependencies. It uses Flexbox.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
