Positioning Schemes
Break elements out of the normal document flow to create overlays, sticky headers, and fixed floating buttons.
What it is
By default, browsers place HTML elements onto the page one after another, from top to bottom. This is called the 'normal document flow'.
The position property allows you to hijack this behavior. You can nudge an element away from its original spot, remove it from the flow entirely so other elements ignore it, or lock it to the screen so it never scrolls away.
Why it matters
Complex UI patterns are impossible with normal flow alone. If you want a navigation bar that stays visible as the user scrolls, a modal dialog that hovers over the page, or a notification badge that sits exactly on the top-right corner of an icon, you must use CSS positioning.
How it works
There are five main values for the position property:
1. **static**: The default. The element stays in normal flow. The top, right, bottom, and left properties have absolutely no effect.
2. **relative**: Stays in normal flow, but you can visually nudge it using top/left. Importantly, it acts as an 'anchor' for any absolutely positioned children inside it.
3. **absolute**: Completely removed from the normal flow. It positions itself relative to its closest *positioned* ancestor (any parent that isn't static).
4. **fixed**: Removed from the flow and locked to the browser viewport. It stays on screen even when the user scrolls.
5. **sticky**: A hybrid. It acts like static (scrolling normally) until it hits a specified threshold (like top: 0), at which point it 'sticks' to the screen until its parent container scrolls away.
Try it
Select different positioning schemes for the highlighted box. Use the scroll area to see how 'fixed' and 'sticky' behave when the page moves.
The Position Inspector
Position Scheme
Default document flow.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
staticis the default.topandleftdo nothing.relativekeeps the element in flow but allows nudging, and acts as an anchor for absolute children.absoluteremoves the element from flow and anchors it to the nearest positioned parent.fixedlocks the element to the browser screen.stickyscrolls normally until a threshold, then sticks to the screen.
Done with this concept?
Mark it complete to track your progress. No login needed.