The z-index property is usually applied only to positioned elements (relative, absolute, fixed, etc.) https://jsfiddle.net/8e1hxkmy/ There are elements of P and H1, P is under H1 because H1 is set z-index layer priority: 2; Further, P has an embedded element EM, in which the z-index is even larger than that of H1, but since the EM is not positioned, it should not be adjusted to H1, but if its container P is assigned display: flex; So EM immediately begins to build on H1. Why this behavior?
p{ margin-bottom: -30px; position: relative; color: red; display: flex; background: blue; } h1{ position: relative; z-index: 2; background: green; } p em{ background: red; z-index: 3; } <p>13231<em>666</em></p> <h1>Aaaaa</h1>