How does the CSS z-index property work?

Answer

The z-index property controls the stacking order of elements. Higher values appear on top. Only elements with a position other than static have a stacking context.

div {
  position: absolute;
  z-index: 2;
}

Learn more about z-index