1. What sticky really means
A sticky element is still part of the normal flow. It scrolls with the page until it reaches the offset you set, then it stops and stays there while the rest of the document keeps moving.
2. The two ingredients
You need position: sticky and at least one inset. Without an inset the element has nowhere to pin to, so it behaves exactly like a static box.
3. Pair it with scroll-margin
A sticky bar covers the top of the viewport, so jumping to an anchor hides the heading underneath it. scroll-margin-block-start pushes the scroll target down by the height of the bar and the problem is gone.
4. What breaks it
Any ancestor with overflow: hidden, auto or scroll becomes the scroll container. Sticky then pins inside that box — not the viewport — and usually looks like it does nothing at all.
5. Keep scrolling
This last block only exists to make the page tall enough for the pinning to be visible. Notice that the header never leaves the top edge.