Explain the difference between position: relative, absolute, fixed, and sticky.

  • relative: Positions relative to itself.
  • absolute: Positions relative to the nearest positioned ancestor.
  • fixed: Positions relative to the viewport, staying in place while scrolling.
  • sticky: Switches between relative and fixed depending on scroll.