Z-index maximum and minimum value

The z-index is a CSS attribute used to determine the stacking order of HTML-positioned elements.

It represents the z-order of an element’s position and is assigned an integer value, accepting positive, negative, or zero values.

However, it only functions with elements positioned using absolute, relative, and fixed types.

Following is a syntax

z-index: auto | <integer> | inherit;

It can have values such as auto, integer, or inherit from the parent.

Here is an example of stacking one element over another by assigning a higher z-index value

<body>
  <div class="container">
    <div class="box1">box1</div>
    <div class="box2">box2</div>
    <div class="box3">box3</div>
  </div>
</body>
.container {
  position: relative;
}
.box1 {
  z-index: 1;
}
.box2 {
  z-index: 2;
}
.box3 {
  z-index: 3;
}

The z-index value can be any integer in CSS.

According to the CSS specification, there is no strictly defined maximum or minimum value.

However, the maximum value is defined and varies across different browsers.

Certain browsers may encounter issues with stacking orders when dealing with extremely large or small values.

For safety, a commonly used maximum value is a 32-bit signed integer, such as 2147483647. Nevertheless, it practically allows for infinite values.

In some browsers, the safest maximum value is INT_MAX, while WebKit browsers, like Chromium, allow values up to LONG_MAX.

Conclusion

To summarize, the z-index property has no strict limits on maximum and minimum values. However, it is advisable to use safe values to avoid potential issues with element positioning and stacking order in different browsers.