Quick reference

Class
Properties
z-0z-index: 0;
z-10z-index: 10;
z-20z-index: 20;
z-30z-index: 30;
z-40z-index: 40;
z-50z-index: 50;
z-autoz-index: auto;

Basic usage

Setting the z-index

Control the stack order (or three-dimensional positioning) of an element in Tailwind, regardless of order it has been displayed, using the z-{index} utilities.

05
04
03
02
01
<div class="z-40 ...">05</div>
<div class="z-30 ...">04</div>
<div class="z-20 ...">03</div>
<div class="z-10 ...">02</div>
<div class="z-0 ...">01</div>

Using negative values

To use a negative z-index value, prefix the class name with a dash to convert it to a negative value.

<div class="-z-50">
  <!-- ... -->
</div>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:z-50 to only apply the z-50 utility on hover.

<div class="z-0 hover:z-50">
  <!-- ... -->
</div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:z-50 to apply the z-50 utility at only medium screen sizes and above.

<div class="z-0 md:z-50">
  <!-- ... -->
</div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind provides six numeric z-index utilities and an auto utility. You can customize these values by editing theme.zIndex or theme.extend.zIndex in your tailwind.config.js file.

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      zIndex: {
        '100': '100',
      }
    }
  }
}

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off z-index value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

<div class="z-[100]">
  <!-- ... -->
</div>

Learn more about arbitrary value support in the arbitrary values documentation.