---
title: "Portal"
description: "Renders its children at the end of the page body or in an element you pick, so a clipped or turned parent does not trap them."
url: https://gelatinui.com/components/portal
markdown_url: https://gelatinui.com/components/portal.md
access: free
install: "npx shadcn@latest add @gelatin-ui/portal"
registry_item: https://gelatinui.com/r/portal.json
version: "2026-11-08"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Portal

> Renders its children at the end of the page body or in an element you pick, so a clipped or turned parent does not trap them.

Page: https://gelatinui.com/components/portal

## When to use it

Best for: Content with no Base UI popup that must leave its parent: a floating card, a page overlay, or a bar fixed to the screen.

- Use it when a parent with `overflow: hidden`, a `transform`, or a `filter` cuts or moves a `fixed` child.
- Set `container` to render in an element other than the page body.
- Place the content with its own classes (`fixed end-6 bottom-6 z-50`). The Portal sets no place and no `z-index`.

## When not to use it

- For a popup that opens from a trigger, the popup part has its own portal. Use a [Popover](https://gelatinui.com/components/popover.md).
- For a modal window with a focus trap, use a [Dialog](https://gelatinui.com/components/dialog.md).

## Notes for agents

- It renders nothing on the server and during hydration, and at once in a browser mount after it.
- It renders one wrapper `div` with `display: contents`, so the content places itself as if the wrapper was not there.
- Under a right-to-left `DirectionProvider`, the wrapper gets `dir="rtl"`.
- Props go to the wrapper. A class with a `display` (such as `hidden`) replaces `contents`.
- There is no Affix item: a `fixed` class on the child does that job.

## Anatomy

```text
Portal
```

## API reference

### Portal

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `container` | `HTMLElement \| null` |  | Where the content renders. `null` or no value: `document.body`. |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Portal | `portal` |  |  |  |

## Usage

Wrap content that must leave its parent. Place the content with its own classes.

```tsx title="saved-notice.tsx"
import { Portal } from "@/components/ui/portal";

export function SavedNotice() {
  return (
    <Portal>
      <div className="fixed end-6 bottom-6 z-50 rounded-xl border bg-popover p-4">
        Saved to your reading list
      </div>
    </Portal>
  );
}
```

## Compose

Rules:

- Group with a Frame (`group-in-frames`): Put related panels in one `Frame` with its header and footer outside the panels, and keep a plain `Card` for one block of content.
- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui/portal
```

It adds 6 registry items: 6 files, 142 lines, and the npm packages `@base-ui/react`, `clsx`, `tailwind-merge`.

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Popover](https://gelatinui.com/components/popover.md)
- [Dialog](https://gelatinui.com/components/dialog.md)

## Accessibility

The content moves to the end of the page in the DOM, so it comes last in the Tab order. Content that people must reach at once needs its own focus move.
