Is using z-index in your CSS bad practice?

darrenvong

Darren Vong

Posted on September 1, 2019

Is using z-index in your CSS bad practice?

When was the last time you see the z-index CSS property being used like so:

.some-element {
  z-index: 99999999;
}
Enter fullscreen mode Exit fullscreen mode

Now suppose you want another element to be displayed above the element with the "some-element" class, a quick and dirty (yet seemingly common!) fix for this is by adding another '9' at the end of the z-index value above and apply it to this other element. For bigger web apps, this can quickly become unmanageable.

Since the default ordering is determined by the order of the HTML markup, with the element nearest the bottom appearing on top, shouldn't we use that instead of z-index? Can you think of a use case where relying on the markup's order alone is insufficient?

💖 💪 🙅 🚩
darrenvong
Darren Vong

Posted on September 1, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related