# Sticky Sidebar

> A sidebar that sticks while the content scrolls. Scroll inside the preview to see it.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: sticky, sidebar, position sticky, scroll, grid, toc
- Live preview: https://copy-css.com/snippets/sticky-sidebar
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="sticky-layout">
  <aside>Sidebar</aside>
  <main>
    <section>Section 1</section>
    <section>Section 2</section>
    <section>Section 3</section>
    <section>Section 4</section>
  </main>
</div>
```

## CSS

```css
.sticky-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  align-items: start; /* without this, the sidebar stretches and can't stick */
  gap: 32px;
}

.sticky-layout aside {
  position: sticky;
  top: 16px;
}
```

## Notes

- This CSS Sticky Sidebar is 11 lines of pure CSS (0.2 KB) with no JavaScript and no dependencies. It uses CSS Grid and sticky positioning.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
