Sticky Sidebar Layout
Two column layout with a sticky sidebar card that stays visible while scrolling.
Main content
This column scrolls normally with the page. Put your article, product details, or dashboard content here.
<div class="flex flex-col md:flex-row gap-4 w-full">
<main class="flex-1 rounded-xl bg-white border border-slate-200 p-5 shadow-sm">
<h3 class="font-semibold text-slate-900 mb-2">Main content</h3>
<p class="text-sm text-slate-600 leading-relaxed">This column scrolls normally with the page. Put your article, product details, or dashboard content here.</p>
</main>
<aside class="md:w-52 shrink-0">
<div class="sticky top-4 rounded-xl bg-slate-900 text-white p-5">
<h4 class="font-semibold mb-2">Sticky card</h4>
<p class="text-sm text-slate-300">This card stays pinned while you scroll past.</p>
</div>
</aside>
</div>Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Left sidebar
Put the sticky card on the left for docs and dashboards where navigation lives on that side.
Main content
This column scrolls normally with the page. Put your article, product details, or dashboard content here.
Table of contents
The table-of-contents sidebar keeps long articles navigable without scrolling back up.
Main content
This column scrolls normally with the page. Put your article, product details, or dashboard content here.
Pricing CTA
A sticky pricing card keeps the upgrade button visible while visitors read the feature list.
Main content
This column scrolls normally with the page. Put your article, product details, or dashboard content here.
About this sticky sidebar layout
A sticky sidebar keeps secondary content pinned in view while the main column scrolls. Tables of contents, signup cards, buy boxes, and filter panels all live in this pattern, and it is one of the most common layouts on docs sites and blogs.
The structure is a flex row where the main column takes flex-1 and the aside gets a fixed width. The inner card uses sticky top-4, which pins it one rem below the viewport top once you scroll past it. On mobile the columns stack, so nothing gets squeezed into an unusable sliver.
Use it when the sidebar holds actions you want always reachable. Keep the sticky card shorter than the viewport height, or its bottom edge will stay permanently out of reach. If the sidebar content is taller than the screen, let it scroll normally instead of sticking.
Long articles and product pages have a split personality. The main column deserves full attention, but secondary content like a table of contents, a signup card, or a buy box should never scroll out of reach. The sticky sidebar keeps that secondary panel pinned while the main column flows, so the call to action is always one glance away no matter how deep the user reads.
The structure is a flex row where the main column takes flex-1 and the aside gets a fixed width. The inner card uses sticky with top-4, pinning it one rem below the viewport top once scrolled past. On mobile the columns stack so nothing gets squeezed into an unusable sliver. The top offset is the critical number: it must clear any fixed navbar.
The classic sticky failure is an ancestor with overflow-hidden anywhere up the tree; it silently disables sticking with no console warning, and developers debug the aside for hours. Check every parent up to body when sticky refuses to stick. Give the sticky element align-self: flex-start, or it stretches to the row height and has nowhere to travel. Set the top offset to clear your fixed header plus breathing room; a sidebar kissing the navbar looks like a z-index bug.
The footer collision is the visual bug: the sticky panel holds its position and slides right over the footer, covering links and looking broken. Fix it by constraining the sticky range, either with a parent that ends where the footer begins, or by releasing the panel near the page bottom with an IntersectionObserver. Sticky should mean pinned within its section, not glued to the viewport forever.
Where to use it
- ✓ Blog articles with a table of contents
- ✓ Documentation pages with on-this-page navigation
- ✓ Product pages with a sticky buy box
- ✓ Dashboards with a sticky filter panel
Customization tips
Adjust top-4 to clear a fixed navbar, for example top-20 under a four rem header. Widen the aside with md:w-64 for roomier cards. One hard rule: no ancestor may have overflow-hidden, because that breaks sticky positioning entirely.
Design notes
When to use
A sticky sidebar earns its place on long pages where secondary content should stay reachable, like a table of contents in documentation, a buy box on a product page, or filter controls on a listing page. It keeps the one thing the visitor keeps needing pinned while the main column scrolls freely. The pattern pays off most when the sidebar holds an action, not just decoration.
What to avoid
Do not make the sidebar taller than the viewport, because then its bottom content is unreachable while it is stuck. Do not keep a sidebar on mobile layouts, where it steals width from the content people came to read. And remember the hard rule from the code: no ancestor may have overflow hidden, or the sticky behavior silently dies.
Accessibility
Make sure everything in the sticky sidebar stays keyboard reachable and that it never covers main content when the page is zoomed to 200 percent. Sticky elements should not trap focus or overlap the text column on narrow screens.
Frequently asked questions
Why is my sticky sidebar not sticking?
The most common cause is overflow-hidden or overflow-auto on a parent element, which turns that parent into the scroll container. Remove it, or position sticky relative to that container instead.
Should sticky go on the aside or on an inner div?
Put sticky on an inner div, not the aside itself. The aside defines the column height, while the inner card sticks within it and releases naturally when the column ends.
Does sticky work on mobile?
Yes, but this layout stacks the columns on small screens, so the sidebar appears below the content. That is usually better than a cramped pinned column on a phone.
Should I use position sticky or fixed for a sidebar?
Use sticky when the sidebar belongs to a content column and should scroll away with the page footer. Use fixed when it must stay visible no matter how far the user scrolls, like an app shell nav. Sticky respects document flow, so it never overlaps the footer, which is the most common fixed-sidebar bug.
Why does overflow hidden on the parent break sticky?
Any overflow value other than visible on an ancestor creates a new scroll container, and sticky positions relative to the nearest one. If that ancestor is only as tall as the sidebar itself, there is no room to stick. Remove the overflow or move the sticky element outside that wrapper.
How much top offset should a sticky sidebar have?
Match it to your fixed header height plus a comfortable gap, commonly 16 to 24px below the header. Too small and the sidebar slides under the header, too large and it looks detached. If the header height changes on scroll, set the offset with a CSS variable you update in one place.
Related elements
Marquee Ticker
Infinite scrolling logo/text ticker, pure CSS.
2024
Launched v1.0
First public release with core features.
2025
Reached 10k users
Community growth milestone.
2026
What's next
Roadmap in progress.
Vertical Timeline
Clean vertical timeline with dots and connecting line.
What is your return policy? +
You can return any item within 30 days of purchase for a full refund. No questions asked.
How long does shipping take? +
Standard shipping takes 3-5 business days. Express options are available at checkout.
Do you ship internationally? +
Yes, we ship to over 50 countries. Rates are calculated at checkout.
Accordion
Smooth FAQ accordion with plus/minus icons.