codegurukool.com · Free coding tutorials & online compiler

Home › CSS Tutorial › CSS z-index

CSS z-index

Stack overlapping elements.

Higher z-index sits on top. It works on positioned elements and flex/grid items.

Example code

<style>
div{position:absolute;width:100px;height:80px}
.a{background:tomato;z-index:2;left:20px;top:20px}
.b{background:#2e86de;z-index:1;left:60px;top:50px}
</style>
<div class='a'>Top</div><div class='b'>Under</div>

Run this code in the online editor

← Position offsetsCSS overflow →