src/docs/z-index.mdx
import { ApiTable } from "@/components/api-table.tsx"; import { Example } from "@/components/example.tsx"; import { Figure } from "@/components/figure.tsx"; import { UsingACustomValue, ResponsiveDesign } from "@/components/content.tsx";
export const title = "z-index"; export const description = "Utilities for controlling the stack order of an element.";
<ApiTable rows={[ ["z-<number>", "z-index: <number>;"], ["z-auto", "z-index: auto;"], ["z-[<value>]", "z-index: <value>;"], ["z-(<custom-property>)", "z-index: var(<custom-property>);"], ]} />
Use the z-<number> utilities like z-10 and z-50 to control the stack order (or three-dimensional positioning) of an element, regardless of the order it has been displayed:
<!-- [!code classes:z-40,z-30,z-20,z-10,z-0] -->
<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:
<Figure> <Example> { <div className="isolate flex justify-center -space-x-3 font-mono text-sm leading-6 font-bold text-white"> <div className="flex size-16 items-center justify-center rounded-full bg-fuchsia-500 shadow-lg outline-2 outline-white dark:outline-[#11121E]"> 01 </div> <div className="flex size-16 items-center justify-center rounded-full bg-fuchsia-500 shadow-lg outline-2 outline-white dark:outline-[#11121E]"> 02 </div> <div className="-z-10 flex size-16 items-center justify-center rounded-full bg-fuchsia-500 shadow-lg outline-2 outline-white dark:outline-[#11121E]"> 03 </div> <div className="flex size-16 items-center justify-center rounded-full bg-fuchsia-500 shadow-lg outline-2 outline-white dark:outline-[#11121E]"> 04 </div> <div className="flex size-16 items-center justify-center rounded-full bg-fuchsia-500 shadow-lg outline-2 outline-white dark:outline-[#11121E]"> 05 </div> </div> } </Example><!-- [!code classes:-z-10] -->
<div class="...">05</div>
<div class="...">04</div>
<div class="-z-10 ...">03</div>
<div class="...">02</div>
<div class="...">01</div>