🎨 The Sticky Header That Un-Sticks Itself Halfway Down
position: sticky only sticks relative to its nearest scrolling ancestor, and that ancestor is determined by the first parent in the chain whose overflow property is set to anything other than the default visible – including a value as seemingly unrelated as overflow: hidden applied purely to clip a decorative shadow, or overflow-x: hidden added somewhere up the tree to stop a layout from scrolling sideways. Once any ancestor sets that property, the sticky element’s scrolling context becomes that ancestor’s box instead of the page, and it stops sticking the instant you scroll past that ancestor’s own boundary – which, depending on layout, can be most of the way down a long page.
🔎 The Problem
.page-wrapper {
/* added only to stop a decorative box-shadow from bleeding
past the wrapper's rounded corners on one section */
overflow: hidden;
}
.site-header {
position: sticky;
top: 0;
z-index: 100;
}
/* .site-header is inside .page-wrapper in the markup */
/* Result: the header sticks correctly at first, then stops sticking
and scrolls away entirely once the page scrolls past the bottom
edge of .page-wrapper's own box - because overflow: hidden made
.page-wrapper, not the viewport, the header's scrolling container */
✅ Fix: Find the Ancestor That Accidentally Became the Scroll Container
- Walk up the DOM from the sticky element in DevTools and check every ancestor’s computed overflow, overflow-x, and overflow-y values – the first one that isn’t visible is the actual scrolling container the sticky element is bound to, regardless of which element you’d intuitively assume is responsible.
- If the overflow was only added for a visual effect (clipping a shadow, hiding an intentional horizontal scrollbar on one specific element), move that overflow declaration onto a more tightly scoped wrapper that doesn’t also contain the sticky element, so the clipping effect survives without becoming the sticky element’s scroll boundary.
- When the overflow genuinely needs to live on an ancestor that also must contain the sticky element, restructure the sticky header to live outside that ancestor in the markup instead (a common pattern: move it to be a direct sibling higher up the tree, styled to visually overlap the section it used to be nested inside).
🚨 Why This Is Dangerous
- Because the sticky behavior still works correctly for the first portion of the scroll, this usually isn’t caught until someone scrolls far enough down a long page during manual testing – a quick check near the top of the page looks completely fine and gives no indication the behavior breaks further down.
- The overflow property responsible is very often unrelated code added much earlier for an entirely different visual reason, sitting several component layers away from the sticky element itself – debugging by staring at the sticky element’s own CSS alone will never find it, since the actual cause lives in a completely different part of the stylesheet.
position: sticky was never promising to stick to the page – it was promising to stick to its nearest scrolling ancestor, and overflow: hidden anywhere up the tree is exactly what quietly redefines which ancestor that is.

