Portal
In one line
A portal lets you render a component's children into a DOM node that exists outside the parent's DOM hierarchy.
In simple words
Portals provide a way to render children into a DOM node that is outside the current component's DOM tree. You create one with ReactDOM.createPortal(children, container), where container is a real DOM element elsewhere in the document.
The most common use case is modals, dialogs, and tooltips — these need to visually escape their parent's overflow: hidden or z-index stacking context. With a portal, the modal renders into document.body while still behaving as if it were inside the React component tree (events bubble up normally).
Even though a portal's DOM is elsewhere, its React tree position is unchanged. This means context, event bubbling, and refs all work as if the portal child were inside the parent.
Example
function Modal({ children }) {
return ReactDOM.createPortal(
<div className="modal">{children}</div>,
document.body
);
}The modal's DOM is appended to document.body, escaping any parent overflow or z-index constraints, but it remains in the React tree.
Related terms
Related Resources
Related Lessons
- Portals
Learn portals for modals and overlays.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.