# Sidebar Layout

> A sidebar that sits beside the content and stacks automatically when space runs out.

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

## HTML

```html
<div class="with-sidebar">
  <div>Sidebar</div>
  <div>Main content</div>
</div>
```

## CSS

```css
.with-sidebar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

/* Sidebar: wants to be about 240px wide */
.with-sidebar > :first-child {
  flex-basis: 240px;
  flex-grow: 1;
}

/* Content: takes the rest, wraps below when narrower than 60% */
.with-sidebar > :last-child {
  flex-basis: 0;
  flex-grow: 999;
  min-inline-size: 60%;
}
```

## Notes

- This CSS Sidebar Layout is 18 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.
