
Description
svelte-portal is a Svelte component for rendering content outside the DOM position of its parent. The Portal component moves its content to a target, which can be an element or a CSS selector for an element that already exists, such as #modals. If no target is given, it uses document.body. The same behavior is also available as a Svelte action that you apply to an element directly. With server-side rendering, the element carries a hidden attribute until the portal has moved it, so you need to set that attribute yourself. TypeScript users should import the component from svelte-portal/src/Portal.svelte to get typing support. The README credits a Svelte issue discussion as the source of the idea. The project is open source and hosted on GitHub.…
Highlights
- Render content outside its parent in the DOM
- Target any element or CSS selector
- Portal action for elements directly
- Works with server-side rendering
Ratings & Reviews
No ratings yet
Be the first to rate svelte-portal.
People also visit
svelte-portal FAQ
What is svelte-portal?
A Svelte component that renders its content outside its parent's place in the DOM.
Where does the content go?
To the target you give it, such as an element or a CSS selector like #modals. If you give no target, it goes to document.body.
Can I use it without a component?
Yes. A portal action applies the same behavior to a DOM element directly.
Does it work with TypeScript?
Yes. Import the component from svelte-portal/src/Portal.svelte to get typing support.
What are the best svelte-portal alternatives?
Popular alternatives to svelte-portal include @rgossiaux/svelte-headlessui, portal-vue and Svelte (shadcn-svelte). See all svelte-portal alternatives











