Difference between position:sticky and position:fixed?

position: fixed always fixates an element to some position within its scrolling container or the viewport. No matter how you scroll its container, it will remain in the exact same position and not affect the flow of other elements within the container.

Without going into specific details, position: sticky basically acts like position: relative until an element is scrolled beyond a specific offset, in which case it turns into position: fixed, causing the element to “stick” to its position instead of being scrolled out of view. It eventually gets unstuck as it gets scrolled back toward its original position. At least, that’s how I understand it in theory.

The reason why I want to avoid going into details is because position: sticky is brand new, experimental (as shown in the document you link to), and not finalized yet. Even what I’ve stated above may well change in the near future. You won’t be able to use position: sticky yet anyway (hopefully this will change within the next year).

Mozilla recently presented its implementation of position: sticky here. It’s highly worth a watch.

Leave a Comment