The z-index property does not apply to all CSS properties that create a new stacking context. In fact, it only works with the following:

  1. Positioned Elements;
  2. Flex Items;
  3. Grid Items.

This means that, z-index will not work if an element does not have position other than static, or it's not a flex item or grid item.

Properties that create a new stacking context only affect the stacking order, blending, compositing, transformation, clipping, masking, and transparency of elements within that context. For z-index this means that, if z-index is applied to elements within a stacking context, their stacking order will be determined relative to the parent, isolated from elements outside the stacking context it is in.

Published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing.