The default positioning. Elements appear in the normal document
flow.
position: static;
What is the default position value for HTML elements?
Positioned relative to its normal position.
position: relative; top: 40px; left: 40px;
How is an element positioned relative to its normal position?
Positioned relative to its nearest positioned ancestor.
position: absolute; bottom: 20px; right: 20px;
Relative to what is an absolutely positioned element positioned?
Positioned relative to the viewport, stays in place while
scrolling.
position: fixed; top: 20px; right: 20px;
What is the behavior of a fixed-positioned element during scrolling?
Acts like relative positioning until a scroll threshold, then
becomes fixed.
position: sticky; top: 20px;
Describe the behavior of a sticky positioned element.
The z-index property controls the vertical stacking order of elements that overlap. It only works on positioned elements (relative, absolute, fixed, or sticky).
In this example, we have three boxes with different z-index
values:
Red box: z-index: 1;
Blue box: z-index: 2;
Green box: z-index: 3;
Which property controls the stacking order of overlapping elements?
Access these helpful resources to aid your learning:
Click the buttons below to see how different positioning affects the layout flow. Watch how other elements adjust their positions when Block 2 is positioned absolutely. Use the z-index slider to control the stacking order of Block 2 when using relative positioning, and observe how it can move behind or in front of Block 3.
Notice: When Block 2 is set to absolute positioning, Blocks 3-6 move up to fill the space, demonstrating how elements are removed from the normal document flow. When using relative positioning, try adjusting the z-index to see how Block 2 can move behind or in front of Block 3 (which has a z-index of 2).