Sticky offset
top, inset-block-start or similar value decides where sticking begins.
Sticky positioning lets an element scroll normally until it reaches an offset, then it sticks within its scroll container.
.sidebar {
position: sticky;
inset-block-start: 1rem;
}
Layout
position: sticky keeps an element in normal flow until the scroll position reaches a defined inset such as top: 1rem.
Sticky positioning depends on the scroll container and available space. It can fail when ancestors have overflow settings or when there is not enough scroll area.
Sticky is useful for sidebars, section labels, table headers and local navigation, but it should not cover content or become distracting.
top, inset-block-start or similar value decides where sticking begins.
Sticky works relative to the nearest relevant scrolling ancestor.
The sticky element still occupies its original layout space.
overflow ancestors and short containers often explain sticky bugs.
Visual model
Good layout CSS is not a pile of positions. It is a set of relationships: flow, axis, tracks, placement, layering, sticking and rhythm.
The element starts in normal document flow.
It sticks when it reaches the top offset.
It stops when the containing area ends.
The next section can take over.
Examples
.sidebar {
position: sticky;
inset-block-start: 1rem;
}
.page { overflow: hidden; }
.sidebar { position: sticky; top: 0; }
/* Sticky may not behave as expected */
Rules that matter
Layout work is where real content, real devices and real users expose weak assumptions. The goal is a structure that explains itself in code and survives change.
Sticky needs a top or logical inset value to know where to stick.
overflow hidden, auto or scroll can change sticky behavior.
Sticky needs enough scrollable space to be visible.
Use offsets and z-index carefully.
Sticky works well inside sections and sidebars.
Sticky UI can consume too much vertical space on small screens.
Production thinking
Sticky elements keep context visible while users scroll, which can make long pages easier to navigate.
Sticky headers should not hide focused content or reduce the usable viewport too much.
Use sticky sparingly and test scroll containers carefully. Most sticky bugs are ancestor or height issues.
Sticky navigation can improve content discovery, but avoid covering important text on mobile.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, change the lab layout and inspect the result.
Senior audit upgrade
position: sticky depends on scroll containers and available space. A parent with overflow can change the scroll reference.
Sticky needs top, bottom, inset-block-start or similar offset.
Check parent overflow when sticky refuses to stick.
The sticky element needs room inside its containing block.