🎨 CSS: Fix position: sticky Refusing to Stick Inside a Scroll Box
Sticky positioning computes “stuck” relative to the element’s nearest scrolling ancestor. If any ancestor between the sticky element and that scroll container has overflow set to anything other than visible — including overflow-x or overflow-y alone, added for an entirely unrelated reason like clipping a decorative shape — the browser treats that ancestor as its own clipping context, and the sticky element can only ever be “stuck” within that ancestor’s bounds. Often that ancestor is exactly as tall as its content, leaving no room for the sticky element to travel through at all.
🔎 The Problem
.layout {
display: flex;
overflow: hidden; /* added months ago to clip an unrelated background shape */
}
.sidebar {
position: sticky;
top: 20px; /* never actually sticks, no matter how far the page scrolls */
}
✅ Fix: Audit Every Ancestor’s overflow Value
- Audit every ancestor between the sticky element and the actual scrolling container for any overflow value other than
visible— either axis alone triggers the same clipping behavior as setting both. - If an ancestor needs
overflow: hiddenfor its own reason, move that overflow onto a dedicated wrapper outside the sticky element’s actual ancestor chain, rather than applying it to a container both elements depend on. - Confirm the sticky element’s direct parent actually has enough height for the sticky behavior to be visible — a sticky child inside a parent exactly as tall as the child itself has nowhere to travel regardless of overflow, which looks identical to the overflow bug but needs a different fix.
🚨 Why This Is Dangerous
- This overflow conflict often comes from a completely unrelated style rule added months earlier for a different component, so “just removing sticky and re-adding it” never fixes anything and can send you looking in the wrong file entirely.
position: sticky doesn’t fail quietly because of its own rule — it fails because of an overflow value sitting several ancestors away that has nothing to do with it.

