z-index

Stacking Order

Example

Positioned elements can overlap. z-index decides which one is on top (higher wins):

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    div { position: absolute; width: 120px; height: 80px; color: white; font-family: Arial; padding: 6px; }
    .a { background: #1971c2; top: 10px; left: 10px; z-index: 1; }
    .b { background: #04AA6D; top: 40px; left: 60px; z-index: 3; }
    .c { background: tomato; top: 70px; left: 110px; z-index: 2; }
  </style>
</head>
<body>

<div class="a">z-index 1</div>
<div class="b">z-index 3</div>
<div class="c">z-index 2</div>

</body>
</html>

Result

Note: z-index only works on positioned elements (and flex/grid items). It also only compares elements inside the same stacking context; a child can never rise above its parent's context.