How to create a sidebar that’s sticky but also scrolls
To make a sidebar fixed but also accommodate screens that are not tall enough to contain the entire sidebar, use this CSS:
.sidebar {
position: sticky;
top: 0;
height: 100vh;
overflow-y: auto;
}
Using Tailwind CSS:
<div class='sticky top-0 h-screen overflow-y-auto'>
...
</div>
→ Get my CSS Handbook
→ I wrote 17 books to help you become a better developer:
- C Handbook
- Command Line Handbook
- CSS Handbook
- Express Handbook
- Git Cheat Sheet
- Go Handbook
- HTML Handbook
- JS Handbook
- Laravel Handbook
- Next.js Handbook
- Node.js Handbook
- PHP Handbook
- Python Handbook
- React Handbook
- SQL Handbook
- Svelte Handbook
- Swift Handbook
Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025