← Cheat Sheets
CSS Positioning and Layering
Position values and z-index.
# CSS Positioning and Layering
Position values and z-index.
| Value | Behavior |
|---|---|
| `static` | Normal flow (default) |
| `relative` | Offset from its normal place; anchors absolute children |
| `absolute` | Positioned against nearest positioned ancestor |
| `fixed` | Positioned against the viewport |
| `sticky` | Normal until a scroll threshold, then sticks |
```css
.badge { position: absolute; top: 0; right: 0; } /* inside a position: relative parent */
.header { position: sticky; top: 0; z-index: 10; }
.overlay { position: fixed; inset: 0; } /* top/right/bottom/left: 0 */
```
`z-index` only works on positioned elements (and flex/grid items) and creates stacking contexts.