CSS Z-index

<!DOCTYPE html>
<html>
<head>
  <title>CSS z-index Example</title>
  <style>
    .box {
      position: relative;
      width: 200px;
      height: 200px;
      background-color: #f2f2f2;
      border: 1px solid #ccc;
      margin: 10px;
    }

    .box-1 {
      z-index: 1;
    }

    .box-2 {
      z-index: 2;
    }

    .box-3 {
      z-index: 3;
    }
  </style>
</head>
<body>
  <div class="box box-1">Box 1 (z-index: 1)</div>
  <div class="box box-2">Box 2 (z-index: 2)</div>
  <div class="box box-3">Box 3 (z-index: 3)</div>
</body>
</html>

Code Output

CSS Z-index

The z-index property in CSS is used to control the stacking order of positioned elements. The higher the z-index value, the closer the element is to the viewer and the more it will overlap other elements.