# Z-Ordering

> How Laioutr prevents z-index conflicts between sections and how to use z-index tokens for sticky or fixed elements.

You build a hero section with `z-index: 10` on its navigation arrows. A content manager drags a product grid section below it. The arrows now paint over the grid. This is a z-index leak: values inside one section escape and break sibling sections. Laioutr prevents this with **section isolation** and a **z-index token scale**.

## Section isolation

Every section gets its own CSS stacking context via `isolation: isolate` on the section root. Z-index values inside your section cannot leak out and affect neighboring sections.

Portaled content (reka-ui `DropdownMenu`, `Sheet`, `Dialog`, `AlertDialog`) is unaffected by section isolation because it renders outside your section's DOM tree via a portal to `<body>`.

### The `#__nuxt` root

The Nuxt app root (`#__nuxt`) also receives `isolation: isolate`. This creates a stacking boundary between the app content and portaled elements at `<body>` level. Any portaled element with a positive z-index appears above the entire app.

### How it fits together

#### Diagram: Section isolation and portaling architecture

```json
[
  {
    "type": "text",
    "id": "title",
    "text": "Section Isolation + Portaling Architecture"
  },
  {
    "type": "rectangle",
    "id": "body_rect"
  },
  {
    "type": "text",
    "id": "body_label",
    "text": "<body>"
  },
  {
    "type": "rectangle",
    "id": "nuxt_rect"
  },
  {
    "type": "text",
    "id": "nuxt_label",
    "text": "#__nuxt"
  },
  {
    "type": "text",
    "id": "nuxt_isolation_label",
    "text": "isolation: isolate"
  },
  {
    "type": "rectangle",
    "id": "s1_rect"
  },
  {
    "type": "text",
    "id": "s1_title",
    "text": "Section 1"
  },
  {
    "type": "text",
    "id": "s1_isolation",
    "text": "isolate: false"
  },
  {
    "type": "rectangle",
    "id": "s1_child_rect",
    "boundElements": [
      "s1_child_text"
    ]
  },
  {
    "type": "text",
    "id": "s1_child_text",
    "text": "Sticky header\nposition: sticky",
    "containerId": "s1_child_rect"
  },
  {
    "type": "text",
    "id": "s1_escapes",
    "text": "z-index escapes to parent"
  },
  {
    "type": "rectangle",
    "id": "s2_rect"
  },
  {
    "type": "text",
    "id": "s2_title",
    "text": "Section 2"
  },
  {
    "type": "text",
    "id": "s2_isolation",
    "text": "isolation: isolate"
  },
  {
    "type": "rectangle",
    "id": "s2_child_rect",
    "boundElements": [
      "s2_child_text"
    ]
  },
  {
    "type": "text",
    "id": "s2_child_text",
    "text": "Hero slider\nz-index: 10",
    "containerId": "s2_child_rect"
  },
  {
    "type": "text",
    "id": "s2_trapped",
    "text": "trapped inside section"
  },
  {
    "type": "line",
    "id": "s2_trapped_line"
  },
  {
    "type": "rectangle",
    "id": "s3_rect"
  },
  {
    "type": "text",
    "id": "s3_title",
    "text": "Section 3"
  },
  {
    "type": "text",
    "id": "s3_isolation",
    "text": "isolation: isolate"
  },
  {
    "type": "rectangle",
    "id": "s3_child_rect",
    "boundElements": [
      "s3_child_text"
    ]
  },
  {
    "type": "text",
    "id": "s3_child_text",
    "text": "Product grid",
    "containerId": "s3_child_rect"
  },
  {
    "type": "rectangle",
    "id": "s3_popover_rect",
    "boundElements": [
      "s3_popover_text"
    ]
  },
  {
    "type": "text",
    "id": "s3_popover_text",
    "text": "Popover trigger",
    "containerId": "s3_popover_rect"
  },
  {
    "type": "text",
    "id": "portal_area_label",
    "text": "Portaled to <body>"
  },
  {
    "type": "text",
    "id": "portal_area_subtitle",
    "text": "outside #__nuxt stacking context"
  },
  {
    "type": "rectangle",
    "id": "portal_area_rect"
  },
  {
    "type": "rectangle",
    "id": "portal_overlay_rect",
    "boundElements": [
      "portal_overlay_text"
    ]
  },
  {
    "type": "text",
    "id": "portal_overlay_text",
    "text": "Overlay\nz: 1000",
    "containerId": "portal_overlay_rect"
  },
  {
    "type": "rectangle",
    "id": "portal_popover_rect",
    "boundElements": [
      "portal_popover_text"
    ]
  },
  {
    "type": "text",
    "id": "portal_popover_text",
    "text": "Popover portal\nz: 1200",
    "containerId": "portal_popover_rect"
  },
  {
    "type": "rectangle",
    "id": "portal_toast_rect",
    "boundElements": [
      "portal_toast_text"
    ]
  },
  {
    "type": "text",
    "id": "portal_toast_text",
    "text": "Toast\nz: max",
    "containerId": "portal_toast_rect"
  },
  {
    "type": "arrow",
    "id": "arrow_portal",
    "boundElements": [
      "1rZw-04475DWDr_mNz139"
    ],
    "startBinding": "s3_popover_rect",
    "endBinding": "portal_popover_rect"
  },
  {
    "type": "text",
    "id": "1rZw-04475DWDr_mNz139",
    "text": "teleported",
    "containerId": "arrow_portal"
  },
  {
    "type": "text",
    "id": "bottom_note",
    "text": "Each section creates its own stacking context via isolation: isolate.\nPortaled elements escape section isolation and stack against <body>."
  }
]
```

Section z-index values (like the hero slider's `z-index: 10`) are trapped inside their section's stacking context. Portaled elements sit at `<body>` level with z-index values from the token scale, above the entire `#__nuxt` app.

## Z-index tokens

Use the provided CSS custom properties instead of hardcoded z-index values:

<table>
<thead>
  <tr>
    <th>
      Token
    </th>
    
    <th>
      Value
    </th>
    
    <th>
      Use case
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        --z-index-sticky
      </code>
    </td>
    
    <td>
      <code>
        100
      </code>
    </td>
    
    <td>
      Sticky headers, fixed filter bars
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --z-index-modal
      </code>
    </td>
    
    <td>
      <code>
        1400
      </code>
    </td>
    
    <td>
      Sheet, dialog, alert dialog (overlay and content)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --z-index-popover
      </code>
    </td>
    
    <td>
      <code>
        1500
      </code>
    </td>
    
    <td>
      Dropdown menus, select menus, popovers
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --z-index-tooltip
      </code>
    </td>
    
    <td>
      <code>
        1600
      </code>
    </td>
    
    <td>
      Tooltips
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        --z-index-toast
      </code>
    </td>
    
    <td>
      <code>
        1700
      </code>
    </td>
    
    <td>
      Toast notifications
    </td>
  </tr>
</tbody>
</table>

```css
.my-sticky-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-index-sticky);
}
```

### Why modals share one z-index

Modal overlays (backdrops) and modal content use the same `--z-index-modal` value. When multiple modals stack (e.g. an alert dialog on top of a sheet), DOM order determines which appears on top, since later portals paint above earlier ones. A separate overlay z-index would cause the second modal's backdrop to slip behind the first modal's content.

## Opting out of isolation

Sections with sticky or fixed positioning that must remain visible above subsequent sections need to opt out of isolation. Otherwise their z-index is trapped inside the section's stacking context and they disappear behind the next section as it scrolls past.

Set `rendering: { isolate: false }` in your [section definition](/apps/app-development/section-definitions):

```ts
export const definition = defineSection({
  component: 'SectionStickyHeader',
  rendering: { isolate: false },
  studio: { label: 'Sticky Header', tags: ['Header'] },
});
```

<warning>

Only disable isolation for sections with sticky or fixed elements that must remain visible above subsequent sections. Disabling it for regular sections reintroduces z-index conflicts between sections.

</warning>

<tip>

If a dropdown or popover inside your section appears behind another section, the overlay is likely not being portaled. All reka-ui overlay components portal to `<body>` by default. Verify that yours do, too.

</tip>
