Layout
Utilities for controlling the stack order of an element.
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.
<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>
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>
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.
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.
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.
module.exports = {
theme: {
extend: {
zIndex: {
'100': '100',
}
}
}
}
Learn more about customizing the default theme in the theme customization documentation.
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.