×

Tailwind CSS Z-index

The tailwind CSS framework is a CSS utility framework that provides classes for managing HTML content with CSS. Tailwind CSS simplifies our design process and makes it responsive across numerous platforms. The z-Index utility is used to control an element's stack order. It's a replacement for the CSS z-index property. As seen in the examples below, this class is used to describe the z-index along the three-dimensional plane.

Tailwind CSS z-index classes

The Tailwind CSS z-index classes are as follows:

  • z-0
  • z-10
  • z-20
  • z-30
  • z-40
  • z-50
  • z-auto

Note: In the abovementioned class, z-0 is the same as the CSS property z-index:0 and so on.

z-0

It is used to give the element a z-index of zero.

Syntax

<element class="z-0">....</element>

Example:

<!DOCTYPE html>
<head>
    <link
    rel="stylesheet"
    href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
        Tutorial and Example
    </h1>
    <b>Z-Index Class - Tailwind CSS </b>
    <div class="flex-column">
        <div class="relative z-0 w-full
                    h-12 bg-red-400"
              style="top: 32px;">0</div>
        <div class="relative z-10 w-full
                    h-12 bg-blue-400">1</div>
        <div class="relative z-20 w-full
                    h-12 bg-yellow-400">2</div>
        <div class="relative z-30 w-full
                    h-12 bg-purple-400">3</div>
        <div class="relative z-40 w-full
                    h-12 bg-green-300">4</div>
        <div class="relative z-50 w-full
                    h-12 bg-gray-400">5</div>
    </div>
</body>
  </html>

Output:

Tailwind CSS Z-index

z-10

It is used to give the element a z-index 10. Along the z-axis, the items seem 10px upside down.

Syntax

<element class="z-10">....</element>

Example:

<!DOCTYPE html>
<head>
    <link
    rel="stylesheet"
    href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
        Tutorial and Example
    </h1>
    <b>Z-Index Class - Tailwind CSS </b>
    <div class="flex-column">
        <div class="relative z-0 w-full
                    h-12 bg-red-400" >0</div>
        <div class="relative z-10 w-full
                    h-12 bg-blue-400" style="top: 32px;">1</div>
        <div class="relative z-20 w-full
                    h-12 bg-yellow-400">2</div>
        <div class="relative z-30 w-full
                    h-12 bg-purple-400">3</div>
        <div class="relative z-40 w-full
                    h-12 bg-green-300">4</div>
        <div class="relative z-50 w-full
                    h-12 bg-gray-400">5</div>
    </div>
</body>
 </html>

Output:

Tailwind CSS Z-index

z-20

It is used to give the element a z-index of 20. Along the z-axis, the items are 20px upside down.

Syntax

<element class="z-20">....</element>

Example:

<!DOCTYPE html>
<head>
    <link
    rel="stylesheet"
    href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
        Tutorial and Example
    </h1>
    <b>Z-Index Class - Tailwind CSS </b>
    <div class="flex-column">
        <div class="relative z-0 w-full
                    h-12 bg-red-400" >0</div>
        <div class="relative z-10 w-full
                    h-12 bg-blue-400">1</div>
        <div class="relative z-20 w-full
                    h-12 bg-yellow-400" style="top: 32px;">2</div>
        <div class="relative z-30 w-full
                    h-12 bg-purple-400">3</div>
        <div class="relative z-40 w-full
                    h-12 bg-green-300">4</div>
        <div class="relative z-50 w-full
                    h-12 bg-gray-400">5</div>
    </div>
</body>
 </html>

Output:

Tailwind CSS Z-index

z-30

It is used to give the element a z-index of 30. Along the z-axis, the items are 30px upside down.

Syntax

<element class="z-30">....</element>

Example:

<!DOCTYPE html>
<head>
    <link
    rel="stylesheet"
    href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css">
</head>
<body class="text-center">
    <h1 class="text-red-600 text-5xl font-bold">
       Tutorial and Example
    </h1>
    <b>Z-Index Class - Tailwind CSS </b>
    <div class="flex-column">
        <div class="relative z-0 w-full
                    h-12 bg-red-400" >0</div>
        <div class="relative z-10 w-full
                    h-12 bg-blue-400">1</div>
        <div class="relative z-20 w-full
                    h-12 bg-yellow-400">2</div>
        <div class="relative z-30 w-full
                    h-12 bg-purple-400" style="top: 32px;">3</div>
        <div class="relative z-40 w-full
                    h-12 bg-green-300">4</div>
        <div class="relative z-50 w-full
                    h-12 bg-gray-400">5</div>
    </div>
</body>
</html>

Output:

Tailwind CSS Z-index

z-40

It is used to give the element a z-index of 40. Along the z-axis, the elements are 40px upside down.

Syntax

<element class="z-40">....</element>

z-50

It is used to give the element a z-index of 50. Along the z-axis, the elements are 50px upside down.

Syntax

<element class="z-50">....</element>

Related Topics

Tailwind CSS Z-index

The tailwind CSS framework is a CSS utility framework that provides classes for managing HTML content with CSS. Tailwind CSS simplifies our design process and makes it responsive across numerous...

4 minutes read.

Tailwind CSS Opacity

This class accepts a lot of value, and all of the properties are covered in class form. We can change the opacity of any element by using this class. The...

1 minute read.

Tailwind CSS Flex Shrink

CSS flexbox is an important element for frontend development. There are two flex-shrink options in Tailwind CSS, and all properties are covered in class form. For quick front-end development, it's...

3 minutes read.

Tailwind CSS Height

This class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS height property. This class is used...

4 minutes read.

Tailwind CSS Container

In Tailwind CSS, a compartment is utilized to fix the maximum width (max-width) of a component to match the min-width of the breakpoint. It comes exceptionally convenient when content must...

2 minutes read.

Tailwind CSS Grid Auto Rows

In tailwind CSS, this class takes multiple values and covers all of the properties in class form. It's a replacement for the grid-auto-rows CSS attribute. The size of the rows...

6 minutes read.

Tailwind CSS Stroke Width

In tailwind CSS, this class takes a large number of values and all of the properties are covered in the form. It is used to specify the width of an...

1 minute read.

Tailwind CSS Grid Auto Flow

In tailwind CSS, this class accepts multiple values, and all of the properties are covered in class form. It is a CSS alternative. The grid-auto-flow property is used in Tailwind...

4 minutes read.

Tailwind CSS Min-Height

In tailwind CSS, this class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Min-Height Property. It...

2 minutes read.

Tailwind CSS Grid Row Start / End

In tailwind CSS, this class takes several values. All of the attributes are covered in the form of a class. In CSS, it's an alternative to the grid-row attribute. It's...

4 minutes read.

Tailwind CSS Align Self

This class accepts a wide range of values. It's a replacement for the CSS Align Self attribute. This class is used to control how a flex or grid item is...

4 minutes read.

Tailwind CSS Grid Template Rows

In tailwind CSS, this class accepts multiple values and all properties are covered in class form. It's the CSS grid-template-row property's replacement. It is used to set the number of...

2 minutes read.

Tailwind CSS Width

The tailwind CSS width class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Width Property. This...

3 minutes read.

Tailwind CSS Space Between

In tailwind CSS, this class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Space Between property....

4 minutes read.

Tailwind CSS Flex Direction

CSS flexbox is an important element for frontend development. CSS has four directions, therefore in tailwind CSS, all of the properties are covered in class form. It's a front-end development...

5 minutes read.

Tailwind CSS Max-Height

This class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Max-Height attribute. It is used to...

3 minutes read.

Tailwind CSS Flex Wrap

CSS flexbox is an important component for frontend development. It is a front-end development alternative to the CSS flex-wrap Property. Note: You must include the flex class in your element before...

4 minutes read.

Tailwind CSS Grid Template Columns

In tailwind CSS, this class accepts multiple values, and all of the properties are covered in class form. It's the CSS grid-template-columns property's replacement. It's used to specify the number...

2 minutes read.

Tailwind CSS Position

The position class acknowledges more than one value in tailwind CSS. It is an option in contrast to the CSS Position property. This class is utilized for controlling how an...

5 minutes read.

Tailwind CSS Order

One of the best features of Tailwind CSS is the Order class, which allows us to order flex and grid objects according to our needs. There are several different order...

2 minutes read.