Overlays

Portal

Headless portal primitive that moves a subtree into a target element while preserving inline rendering as an explicit opt-out.

import { Portal } from '@lostgradient/cinder/portal';
overlayutilities
01

Overview

Moves content into document.body or another host element while keeping inline rendering available as an explicit opt-out.

Usage

svelte
<script lang="ts">
  import Portal from '@lostgradient/cinder/portal';
</script>

<Portal>
  <div>Portaled content</div>
</Portal>

The table above shows the JSON-Schema-facing type; the actual prop type, PortalTargetInput, additionally accepts an HTMLElement. If a selector cannot be resolved after hydration, Portal keeps its children inline and warns in development.

Live preview
02

When to use

Use when
  • Rendering an overlay or floating surface outside the current stacking or overflow context.
  • Building a custom anchored or modal primitive that needs to append content into document.body or a named host.
Avoid when
  • The content should stay in normal document flow or inherit layout from its original parent.
03

Examples

Basic portal

Renders a floating surface through document.body while leaving the trigger inline.

04

Props

Props for portal
NameTypeDefaultDescription
target PortalTargetInput null
disabled boolean false
inheritAttributes boolean true
children required snippet