---
title: "Why is position: sticky not working?"
description: "A sticky element that will not stick almost always has a missing top offset, an ancestor with overflow set, or a parent with no room to scroll. Here is how to find which."
url: https://www.danny.engineering/answer/css/why-is-position-sticky-not-working
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:25:00.000Z
tags: ["CSS"]
---

# Why is position: sticky not working?

## The short answer


`position: sticky` needs an offset such as `top: 0`, and it only sticks within its nearest scrolling ancestor and inside its own parent. If any ancestor has `overflow: hidden`, `auto` or `scroll`, or the parent is no taller than the sticky element, it will look like nothing happens.


```css
.header {
  position: sticky;
  top: 0; /* required */
  z-index: 10;
}
```


## Why it happens


A sticky element behaves like a normal element until its scroll container scrolls it to the offset you set. Then it holds that position, but only while its parent box is still on screen. Three rules follow from that:

1. **It needs a threshold.** Without `top`, `bottom`, `left` or `right`, the browser has no point at which to start sticking.
2. **It sticks to the nearest scroll container.** Any ancestor with `overflow` set to `hidden`, `auto` or `scroll` becomes that container, even if it never actually scrolls. The element then waits for that box to scroll, which never happens, so it never sticks.
3. **It cannot leave its parent.** The sticky element is constrained to its containing block. If the parent is exactly as tall as the sticky element, there is no distance to travel.

## How to fix it


### Add an offset


The most common cause is simply forgetting the offset.


```css
.sidebar {
  position: sticky;
  top: 1rem;
}
```


### Find the ancestor with overflow


Open your browser's developer tools, select the sticky element, and walk up the tree checking the computed `overflow` value of each ancestor. A quick way is to run this in the console with the element selected:


```javascript
let el = $0.parentElement;
while (el) {
  const { overflow, overflowX, overflowY } = getComputedStyle(el);
  if ([overflow, overflowX, overflowY].some((v) => v !== 'visible')) {
    console.log(el, overflow, overflowX, overflowY);
  }
  el = el.parentElement;
}
```


Once you find it, you have a few options:

- Remove the `overflow` rule if it is not needed.
- If you only used `overflow: hidden` to clip content or stop horizontal scrolling, switch to `overflow: clip`. It clips in the same way but does not create a scroll container, so sticky keeps working.

```css
.page {
  overflow-x: clip; /* instead of overflow-x: hidden */
}
```

- If the ancestor really is meant to scroll, that is fine, but the element will stick relative to that box, not the window.

### Give the parent room


In a two-column layout the sidebar's parent is often a flex or grid container. By default flex and grid items stretch to fill the row, so the sticky sidebar becomes as tall as its column and has nowhere to move. Stop it stretching:


```css
.layout {
  display: grid;
  grid-template-columns: 16rem 1fr;
  align-items: start; /* do not stretch the sidebar */
}

.sidebar {
  position: sticky;
  top: 1rem;
}
```


For a single item in Flexbox you can use `align-self: flex-start` on the sticky element.


### Add a z-index and a background


Sticky headers often do work, but content scrolls over the top of them so they seem to vanish. Give the header a background colour and a `z-index` so it paints above the content that follows it.


## Common pitfalls

- **`overflow: hidden`** **on** **`html`** **or** **`body`****.** Often added to stop sideways scrolling. Use `overflow-x: clip` instead.
- **Sticky table headers.** Put `position: sticky` on the `th` cells, not on `thead` or `tr`, for the most consistent results.
- **Using** **`bottom: 0`** **and expecting it to stick to the top.** The offset you choose decides which edge it sticks to.
- **Expecting it to escape its section.** A sticky heading inside a short `section` stops sticking when that section scrolls away. That is by design.
- **Transforms on ancestors.** These do not break sticky by themselves, but they do create a new stacking context, which can affect your `z-index`.

## Related reading

- [MDN: position](https://developer.mozilla.org/en-US/docs/Web/CSS/position)
- [MDN: overflow](https://developer.mozilla.org/en-US/docs/Web/CSS/overflow)
