CSS Position Property Reference

static, relative, absolute, fixed, sticky positioning with stacking context notes.

Reference for CSS position values with containing-block source, stacking context creation, normal-flow effect and scroll behaviour for static, relative, absolute, fixed and sticky.

What does position: absolute position against?

An absolutely positioned element is laid out relative to its containing block, which is the padding box of the nearest ancestor whose position is not static. If no such ancestor exists, it falls back to the initial containing block (the viewport).

Where an element really sits

The position property is the foundation of CSS layout control: it decides whether an element flows normally, shifts visually, or is lifted out of flow and pinned to a containing block. Getting it wrong produces the classic bugs — a fixed element that scrolls, or an absolute element anchored to the wrong parent. This reference explains all five values with their containing block, inset behaviour, flow impact and stacking-context rules.

How it works

The top, right, bottom and left insets (and the inset shorthand) are measured against the element’s containing block, which differs per value:

  • static — default; insets and z-index are ignored, element stays in flow.
  • relative — offset from its in-flow position; original space is preserved.
  • absolute — removed from flow; positioned in the nearest positioned ancestor.
  • fixed — removed from flow; positioned in the viewport (or a transformed ancestor).
  • sticky — in flow until a scroll threshold, then sticks within its scroll container.

Establishing a stacking context matters for z-index: fixed and sticky always create one, while relative/absolute only do so once z-index is not auto. A transform or filter on an ancestor silently reparents fixed descendants — the single most common positioning surprise.

Tips and notes

  • Set position: relative on a parent to anchor absolute children to it.
  • A transform anywhere up the tree can break position: fixed.
  • sticky needs room to move — it does nothing if the container is the same height.
  • static ignores z-index; give an element a positioning value to stack it.