code/tamagui.dev/data/docs/components/z-index/2.0.0.mdx
Tamagui includes an automatic stacking system that ensures overlays like dialogs, popovers, sheets, and tooltips layer correctly without manual z-index management.
When you open overlay components, Tamagui automatically assigns z-index values so that:
This means you typically don't need to think about z-index at all.
Only set zIndex when you need to override the automatic stacking. Common cases:
z-index: 100, overlays need to appear above it (they do by default).// Only if you need to override automatic stacking
<Dialog zIndex={200000}>
...
</Dialog>
All overlay components use the automatic stacking system. Here's where to set zIndex if needed:
| Component | Where to set zIndex |
|---|---|
| Dialog | <Dialog zIndex={...}> |
| AlertDialog | <AlertDialog zIndex={...}> |
| Sheet | <Sheet zIndex={...}> |
| Select | <Select zIndex={...}> |
| Popover | <Popover zIndex={...}> |
| Tooltip | <Tooltip zIndex={...}> |
| Menu | <Menu.Portal zIndex={...}> |
| ContextMenu | <ContextMenu.Portal zIndex={...}> |
| Toast | Via ToastViewport |
By default, components stack in this order (lowest to highest):
Within each category, mount order determines stacking - open a popover, then another, the second is on top.
Nested floating elements automatically stack above their parent:
<Dialog>
<Dialog.Content>
<Tooltip>
<Tooltip.Trigger>
<Button>Hover me</Button>
</Tooltip.Trigger>
<Tooltip.Content>
I appear above the dialog!
</Tooltip.Content>
</Tooltip>
</Dialog.Content>
</Dialog>
The system tracks parent-child relationships through React context, so nested portals always stack correctly.
The stacking system uses two mechanisms:
When multiple overlays open at the same level, each gets an incrementing z-index:
When content opens inside another portal, it reads the parent's z-index from context and adds 1:
This ensures nested content is always visible above its parent, but sibling content opened later can still stack above.
The Portal component powers this stacking system. If building custom overlay components, you can use Portal's stackZIndex prop:
import { Portal } from 'tamagui'
// Enable automatic stacking
<Portal stackZIndex>
</Portal>
// Or use a high base value (like Dialog does)
<Portal stackZIndex={100000}>
</Portal>
See the Portal documentation for more details.