HTML & CSS Masterclass Tutorial

Comprehensive guide to modern HTML and CSS development.

Positioning & Z-Index

Positioning & Z-Index

The position property removes elements from normal document flow or alters their default behavior.

  • Static: Default. Elements render in order.
  • Relative: Positioned relative to its normal static position. Leaves a "ghost" space where it used to be.
  • Absolute: Removed from normal flow. Positioned relative to its closest positioned ancestor (usually a parent with relative).
  • Fixed: Removed from flow. Positioned relative to the browser window (viewport). Stays fixed when scrolling.
  • Sticky: Toggles between relative and fixed depending on scroll position.

Z-Index

Controls the vertical stacking order of elements that overlap. Higher z-index goes on top. Only works on positioned elements!

Try It Yourself

Edit the code below and click Run to see the result live.

Source Code
Result
Topics