CSS position Property
The position property sets how an element is positioned in a document. The top, right, bottom, and left properties determine the final location of positioned elements.
Description & Usage
The position property dictates the positional algorithm used to place an element on screen. Combined with offset properties (top, right, bottom, left) and z-index, it gives precise control over element placement beyond normal document flow.
Understanding position is crucial for building UI components like sticky headers, modal overlays, tooltips, and floating action buttons. Relative positioning keeps an element in the document flow while shifting its visual appearance, whereas absolute positioning removes it entirely from normal flow relative to its nearest positioned ancestor.
Sticky positioning provides a hybrid experience: elements behave as relative until a scroll threshold is crossed, at which point they lock into a fixed position within their containing block.
Property Specifications
| Property Feature | Specification |
|---|---|
| Category | Layout |
| Initial Value | static |
| Inherited | No (not inherited) |
| Applies To | All elements |
Syntax
position: static | relative | absolute | fixed | sticky;Property Values
| Value | Description |
|---|---|
| static | Default. Element follows normal document flow. Top/right/bottom/left and z-index are ignored. |
| relative | Positioned relative to its normal position without affecting neighboring elements. |
| absolute | Removed from normal flow. Positioned relative to nearest positioned ancestor (non-static). |
| fixed | Removed from normal flow. Positioned relative to the browser viewport. |
| sticky | Treated as relative until a scroll threshold is met, then sticks to offset position. |