> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# z-index

APISummary
## Introduction

The z-index CSS property sets the z-order of an element and its descendants or flex items. Overlapping elements with a larger z-index cover those with a smaller one.

:::info

If we want to generate [stacking context](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context), you can add `z-index: 0` to an element. For example, make children follow the scroll by adding `z-index: 0` to the scroll-view

It is not recommended to use z-index in the direct children of list. This may affect the reuse of list. If you use z-index in the list item, the item should be a stacking context.

:::

## Examples

**This is an example below: css-api**

**Entry:** `src/z-index`
**Bundle:** `dist/z-index.lynx.bundle`

```tsx
import { root, useState } from "@lynx-js/react";
import "./index.scss";

const ZIndex = () => {
  const [indices, setIndices] = useState([2, 1, 0, -1, -2]);
  const [show, setShow] = useState(false);

  const containerStyle = {
    zIndex: 0,
    height: "280px",
  };

  const innerContainerStyle = {
    height: "100%",
  };

  const getBlockStyle = (index: number, color: string, top: string, left: string) => ({
    zIndex: indices[index],
    background: color,
    position: "absolute" as const,
    top,
    left,
  });

  const getTextStyle = (show: boolean) => ({
    top: show ? "0" : "80px",
  });

  const handleChange = () => {
    setIndices(show ? [2, 1, 0, -1, -2] : [-2, -1, 0, 1, 2]);
    setShow(!show);
  };

  return (
    <view className="main" bindtap={handleChange}>
      <view className="container" style={containerStyle}>
        <view className="container" style={innerContainerStyle}>
          <view className="block" style={getBlockStyle(0, "#2196F3", "10px", "10px")}>
            <text className="text" style={getTextStyle(show)}>z-index:{indices[0]}</text>
          </view>
          <view className="block" style={getBlockStyle(1, "#4CAF50", "50px", "50px")}>
            <text className="text" style={getTextStyle(show)}>z-index:{indices[1]}</text>
          </view>
          <view className="block" style={getBlockStyle(2, "#9C27B0", "90px", "90px")}>
            <text className="text" style={getTextStyle(show)}>z-index:{indices[2]}</text>
          </view>
          <view className="block" style={getBlockStyle(3, "#FF9800", "130px", "130px")}>
            <text className="text" style={getTextStyle(show)}>z-index:{indices[3]}</text>
          </view>
          <view className="block" style={getBlockStyle(4, "#E91E63", "170px", "170px")}>
            <text className="text" style={getTextStyle(show)}>z-index:{indices[4]}</text>
          </view>
        </view>
      </view>
    </view>
  );
};

root.render(<ZIndex />);

```

v0.11.0



## Syntax

```css
z-index: 0;
z-index: 3;
z-index: 289;
z-index: -1;
```

### Values

- [`<number>`](/next/api/css/data-type/number.md)
  This integer is the stack level of the generated box in the current stacking context.

- Default value
  **auto**

## Formal definition

| Initial value | empty value |
| Applies to | all elements |
| Inherited | no |
| Animatable | no |


## Formal syntax

```
z-index = <integer>
```

## Differences from the Web

The default value of web is auto. Lynx determines whether it is a stacking context by setting z-index property.

## Compatibility

**Compatibility Table**

**Query:** `css.properties.z-index`

[Source](https://github.com/lynx-family/lynx/blob/develop/tools/css_generator/css_defines/147-z-index.json) · [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/z-index)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| z-index | Yes (1.0) | Yes (3.4) | Yes (1.0) | Yes (1.0) | Yes (1.0) | Yes |

**`z-index`**

**Specifications:**

