Sticky sidebar (position: sticky)

A sidebar that scrolls with the page until it reaches the top, stays there, then stops at the end of its section.

sidebar that follows while scrollingtable of contents stays on screensidebar sticks then lets go at the end of the articlemenu scrolls then stickskeep filters visible while I scrollcontents list that rides along with mestiky sidebarposition sticky not working in sidebar

See it

Live demo coming soon

What it is

A sticky sidebar scrolls normally until it reaches a chosen inset, then parks there while the neighboring content continues. Unlike a fixed sidebar, it remains in the layout and stops when the bottom of its containing block arrives.

Use it for article tables of contents, product filters, checkout summaries, and actions that stay useful deep into a page. The contents list that follows you down an MDN or Tailwind docs page is the pattern at its most ordinary. CSS needs position: sticky plus a top value, and a grid or flex item usually needs align-self: start so it does not stretch to the height of its row.

Gotcha: sticky is bounded by its ancestors. A parent with overflow: hidden, auto, or scroll can become the scrolling box, and a sidebar taller than the viewport has nowhere useful to stick. Keep the ancestor chain intentional, cap tall sidebars, and test keyboard focus inside any independently scrolling filter list.

Ask AI for it

Build a two-column article with a sticky table-of-contents aside. Use CSS Grid for the columns and set the aside to position: sticky, top: 1.5rem, align-self: start, max-height: calc(100dvh - 3rem), and overflow: auto. Keep every ancestor free of overflow values that would change the scrolling box. Below 768px, return the aside to position: static and place it in a collapsed details element above the article.

You might have meant

sidebarsidebar railsticky headerscrollspy navresponsive layout