DEV Community

Cover image for CSS is Emotional: z-index and the Hierarchy of Needs
EIO • Emmanuel Imolorhe
EIO • Emmanuel Imolorhe

Posted on

CSS is Emotional: z-index and the Hierarchy of Needs

In the physical world, we all want to be seen. To be acknowledged. To matter. Some days we want to stand at the forefront, commanding attention. Other times, we prefer to recede into the background, letting others take center stage. This interplay of visibility and prominence isn't just a human experience—it's perfectly mirrored in one of CSS's most misunderstood properties: z-index.

z-index: 6 | Understanding z-index

Imagine shuffling papers on a desk. Even though the desk is flat, papers stack in layers—some on top, others below. That's exactly what z-index does on websites. If you're familiar with tools like Canva, PowerPoint, Photoshop, or Figma, you know this feature as "Send to Back" or more accurately, "Arrange" or "Position".

Your screen shows things in width and height, but when elements need to overlap (like a popup appearing over a page), z-index determines what goes on top. Higher numbers rise to the front, lower numbers settle to the back.

You experience this every day: when your phone's notification slides down over everything else, the menu that pops out from the side, or when clicking a photo makes it pop up larger while darkening what's behind it. All of these effects rely on z-index to determine what should appear closest to you, even though everything is technically displayed on your flat screen.

z-index: 5 | The Struggle for Significance

When we set a z-index value, what we're really saying is: "This element matters. It needs to be seen." It's a declaration of importance, a way of saying, "Pay attention to this." Sound familiar? It's like Maslow's hierarchy of needs, where after securing our basic physiological and safety needs, we seek esteem and self-actualization—the need to be recognized, to achieve our potential, to rise above.

.whatsapp-notification {
  z-index: 999;
  /* Please, notice me. This is important. */
}
Enter fullscreen mode Exit fullscreen mode

But here's where it gets interesting: just like in life, prominence in CSS isn't simply about shouting the loudest or climbing the highest. A z-index of 99999 doesn't guarantee visibility, just as being the loudest person in the room doesn't guarantee being heard. Context matters. Stacking contexts, just like the two transparent boxes in the banner above, are like social circles or organizational hierarchies—complex systems where your relative position depends on more than just your individual assertions.

z-index: 4 | The Hidden Complexity of Visibility

Have you ever felt invisible despite your best efforts to be seen? That's the position: static of human interaction. No matter what z-index value you give it, a statically positioned element refuses to leave its place in the document flow. And static is the default position value for all elements in CSS, serving as a humbling reminder that, sometimes, before we can stand out, we may need to step outside our comfort zone:

.dreaming-of-standing-out {
  z-index: 999; /* Big dreams */

  /* This won't work... */
  position: static;
  /* ...because you can't find progress in your comfort zone. */
}

.actually-standing-out {
  z-index: 1; /* Simple steps in the right direction */

  /* This will work */
  position: relative; /* Positioned for greatness */
}
Enter fullscreen mode Exit fullscreen mode

z-index: 3 | The Paradox of Stacking Contexts

Perhaps the most profound lesson z-index teaches us is about perspective and relative truth. What appears "on top" from one vantage point might be completely hidden from another. Each stacking context is like a separate social sphere or cultural context—with its own rules, hierarchies, and definitions of prominence. Again, see the boxes in the banner above.

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

.box-1 > .orange-sheet-with-circle {
  position: absolute;
  z-index: 999999; /* Still won't show above .box-2 */
}

.box-2 {
  position: relative;
  z-index: 2; /* Appears above .child despite lower value */
}
Enter fullscreen mode Exit fullscreen mode

This code reveals a truth about both CSS and life: our perceived importance often depends more on our context than our individual efforts. A modest z-index in the right stacking context can place an element above another with a much higher value—just as quiet wisdom in the right moment can speak louder than grand gestures.

z-index: 2 | Finding Balance in the Stack

Just as we learn to balance our need for recognition with our role in the community, working with z-index teaches us about the delicate balance between standing out and fitting in. Here are some patterns I've learned to code live by:

  1. Start Small: Don't jump to z-index: 9999. Begin with small, intentional numbers. In life and CSS, sustainable prominence comes from measured steps, not dramatic leaps. Of course, there are exceptions—this is simply a "best practice."

  2. Consider Context: Before increasing z-index, check if the stacking context is what needs adjustment. Sometimes, our visibility issues stem from the systems we're operating within, not our individual elevation.

  3. Document Your Intentions: When you do need high z-index values, leave comments explaining why. Future you (and your team) will appreciate understanding the emotional and technical context of these decisions:

/* z-index: 100 - Critical user notifications
   z-index: 50  - Modal overlays
   z-index: 10  - Navigation elements
   z-index: 1   - Standard interactive elements */
Enter fullscreen mode Exit fullscreen mode

z-index: 1 | The Liberation of Letting Go

Perhaps the most liberating realization about z-index is that not everything needs to fight for the highest position. Some elements serve their purpose best at their default stacking level. In life, too, there's peace in accepting that we don't always need to be the most visible, the most prominent, the highest-stacked element in every context.

z-index: 0 | Kairos and Purpose

z-index isn't just a CSS property—it's a mirror reflecting our very human need to be seen, to matter, to rise above. But like all tools that deal with hierarchy and visibility, it teaches us that true prominence isn't about having the highest number. It's about finding the right position, in the right context, at the right time.

The next time you find yourself reaching for z-index: 9999, pause. Ask yourself: What am I really trying to elevate here? Is this about technical layering, or is there something deeper—a need for recognition, for importance, for visibility—that I'm trying to express through code?

Because in the end, the most elegant CSS, like the most fulfilling life, isn't about rising above everything else. It's about finding your proper place in the stack, contributing to the harmony of the whole, and knowing when to step forward—and when to let others shine.


Next week, we'll explore how media queries teach us about adapting to change. Until then, I'd love to hear your thoughts: When was the last time you used z-index? What emotions were driving that decision? Share your stories in the comments below.


Here's the CodePen used to design the banner 😊


About the Author

Emmanuel Imolorhe (EIO) is a Frontend Engineer passionate about CSS.
Check out my CSS videos on YouTube.

Connect with me

TwitterBlueskyMastodonLinkedInWebsite


Did this post help you? Have thoughts to share? Let's continue the conversation in the comments below!

Top comments (0)