Use static for ordinary document flow, relative to offset an element without giving up its space, absolute for an overlay anchored to a containing block, fixed for an element usually anchored to the viewport, and sticky for an element that scrolls normally until it reaches an inset threshold. The crucial choice is not just how far to move a box: it is whether it stays in normal flow and which box its offsets use.
How to choose a CSS position value
| Value | Remains in normal flow? | What the offsets refer to | Typical use |
|---|---|---|---|
static |
Yes; it is the default. | No positioned offset behavior. | Ordinary document layout. |
relative |
Yes; its original space remains reserved. | The element’s normal position. | A small visual adjustment or a local containing block for an absolute child. |
absolute |
No; surrounding layout reserves no space for it. | Its containing block, often the padding box of a suitable ancestor. | A badge or overlay inside a component. |
fixed |
No; surrounding layout reserves no space for it. | Usually the viewport or initial containing block, unless an ancestor establishes a different containing block. | A viewport-level control or panel. |
sticky |
Yes; it keeps its space and initially behaves like a relatively positioned element. | Its nearest ancestor that creates a scrolling mechanism, constrained by its containing block. | A heading or navigation element that stays in view while its section scrolls. |
This is a practical summary; exact containing-block rules have additional cases. See MDN’s position reference and the CSS Positioned Layout Module Level 3.
What each position value does
static: keep ordinary flow
static is the default. The browser lays the element out with the surrounding content; it does not behave as a positioned box for top, right, bottom, or left offsets. Start here unless the layout calls for a specific positioning behavior.
As an Amazon Associate I earn from qualifying purchases.
relative: offset without removing the space
A relatively positioned element remains in normal flow, so its original space is still reserved even if an inset shifts how it is drawn. That can leave an apparent gap at its former location; nearby elements do not move in to fill it.
relative is also commonly used on a wrapper to give an absolutely positioned child a local reference area:
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
.card {
position: relative;
}
.card__badge {
position: absolute;
inset-block-start: 0.5rem;
inset-inline-end: 0.5rem;
}
Here the wrapper is a containing-block candidate because its position is not static. The inset properties place the badge near the wrapper’s block-start and inline-end edges, adapting to writing direction. The MDN positioning tutorial covers this common pattern.
absolute: take an element out of flow
An absolutely positioned element does not take up space in normal layout. Other content is arranged as if it were not there, so an overlay can cover content or leave a hole if its former flow position mattered.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Rank #2
Its insets are measured from a containing block. A common case is the padding box of the nearest ancestor whose position is not static, but that is not the complete rule: properties such as transforms or containment can also establish containing blocks, and layout contexts can matter. If an element appears attached to the page rather than to its component, check the ancestor chain for the intended containing block. The MDN containing-block guide explains the broader rules.
fixed: usually anchor to the viewport
A fixed element is removed from normal flow and is ordinarily positioned relative to the viewport, which can suit controls intended to remain in view during scrolling. But fixed does not always mean viewport-relative: a qualifying ancestor can establish its containing block instead. If a supposedly fixed panel moves with a section, inspect ancestors for transforms and other containing-block-forming properties.
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
sticky: stick after reaching an inset
A sticky element keeps its flow space. It behaves relatively until scrolling reaches an inset threshold, then sticks within the limits of its containing block. For a header that should stick at the top, a typical rule is position: sticky; top: 0;. At least one inset on the axis where it should stick must be non-auto; without a threshold, it will not stick on that axis.
Sticky positioning follows the nearest ancestor that creates a scrolling mechanism, including one with overflow: hidden, scroll, auto, or overlay. That ancestor may not be the one visibly scrolling. The sticky element must also have room to move within its containing block. These details explain many cases where sticky appears not to work; see MDN’s position reference.
Recommended Free Tools
Containing blocks and stacking contexts answer different questions
A containing block answers, “What box are these offsets measured from?” A stacking context answers, “Which group is painted above another?” Treating them as the same problem leads to misplaced boxes and ineffective z-index changes.
For an absolute element, the containing block is commonly established by a non-static positioned ancestor. Other properties can establish one, too; percentages in positioned dimensions or insets may depend on that reference box. For details, see MDN’s containing-block guide.
Rank #4
A positioned element with a non-auto z-index can create a stacking context; fixed and sticky elements create one as well. Stacking contexts are painted as groups. A child with a very large z-index cannot jump above an element in a higher sibling context if its own parent context is painted underneath. Compare the parent contexts before increasing a child’s number. MDN’s stacking-context guide describes the rules.
Why positioning may not behave as expected
- An absolute child is in the wrong place: identify which ancestor establishes its containing block. If the intended wrapper is not a candidate, check its positioning and inspect ancestors for transforms, containment, or relevant layout contexts.
- A fixed item moves during scrolling: check whether an ancestor establishes a containing block for fixed descendants.
- A sticky item never sticks: set a non-
autoinset on the intended axis, locate the nearest ancestor creating a scrolling mechanism, and check whether the containing block gives the item room to stick. z-indexseems ignored: find the stacking context containing each element and compare those contexts, not only the elements’ individual values.- Changing position creates a jump or overlap: check flow behavior. Absolute and fixed remove the element from normal flow; relative and sticky retain its space.
For a broader walkthrough of positioning behavior and examples, see MDN’s positioning tutorial.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




