Preparing your workspace
The position property changes how an element is placed and how it relates to surrounding content.
Static positioning is the normal default behavior. Relative positioning keeps the element in normal flow but allows controlled movement from its original position. Absolute positioning removes the element from normal flow and positions it relative to a suitable positioned ancestor. Fixed positioning places an element relative to the viewport, which is useful for elements that should remain visible while scrolling. Sticky positioning behaves like normal flow until a scroll threshold is reached, after which the element sticks within its scrolling container. Positioning is powerful but should not replace normal layout systems when Flexbox or Grid is more appropriate.
A notification button can be fixed near the bottom of the screen, while a course sidebar can use sticky positioning while the user reads lesson content.
.sidebar {
position: sticky;
top: 20px;
}
.help-button {
position: fixed;
right: 20px;
bottom: 20px;
}The sidebar can remain visible during scrolling, while the help button stays positioned relative to the viewport.