Portals
Learn how React Portals let overlays escape DOM constraints while still behaving as part of the same React tree.
Last reviewed: June 2026
🔍 What Is It?
Portals are used when a component needs to render outside its parent DOM hierarchy.
- →Common for modals, drawers, tooltips, and popovers
- →Avoids clipping, stacking, and overflow problems
- →Keeps React context and event propagation intact
- →Requires deliberate focus and accessibility handling
🎯 Why Do We Need It?
Without portals, overlays often break because a parent has overflow hidden, a lower stacking context, or layout rules that trap the UI inside the wrong container.
🏗️ What Happens in Real Projects?
Production apps use portals for dialogs, command palettes, dropdown menus, toasts, onboarding layers, and support widgets that must visually escape the page layout.
⚙️ How It Works
ReactDOM.createPortal renders the JSX into a target DOM node such as #modal-root. Even though the DOM lives elsewhere, the component still reads context from its original parent and React events bubble through the React tree.
💻 Example
Modal with a Portal Root — A portal solves layering problems, but accessibility still needs to be handled deliberately.
🤔 Common Confusions
❓ Does a portal break context?
No. The portal moves DOM placement, not React tree ownership. Context still works normally.
❓ Do browser events and React events behave the same here?
Not exactly. React events continue through the React tree, which can surprise teams if they only think in DOM-tree terms.
🚨 Common Production Issues
Dialogs that visually open but fail keyboard focus management are inaccessible and hard to use.
Teams solve clipping with portals but forget scroll locking or escape handling.
Multiple overlay systems without one shared portal strategy create z-index wars quickly.
✅ Best Practices
Use a shared portal root strategy for overlays across the app.
Manage focus, escape handling, and scroll locking deliberately.
Test both pointer and keyboard behavior for portal-driven overlays.
Treat overlay layering as a design-system concern, not a one-off component trick.
🏛️ Architect's Note
Portals are easy technically and hard operationally. The real architecture question is who owns overlay governance, focus rules, layering, and cross-product consistency.
💬 Frequently Asked Questions
🎯 Key Takeaways
🔗 Related Topics
🎯 Practice this topic in interviews
↗ Where this topic fits
React Technology Guide
Return to the React learning hub.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Python Developer Career Path
A practical route through Python fundamentals, automation, backend basics, testing, projects, interview preparation, and career growth.
Sources
Sources / References
Use these React references to verify the concept in official docs and continue into the most relevant SplashRide pages.
Official documentation
Related SplashRide pages
SplashRide React learning path
Browse the full React topic collection and learning order on SplashRide.
React Interview Prep
Practice React interview questions and scenario-based answers.
Frontend Engineer Career Path
A beginner-friendly journey through web foundations, React, production frontend engineering, and interview preparation.
Python Developer Career Path
A practical route through Python fundamentals, automation, backend basics, testing, projects, interview preparation, and career growth.
Components
Master React components — the fundamental building blocks of every React application. Learn component design, composition patterns, and how senior engineers structure components in enterprise projects.
Compound Components
Master the Compound Components pattern — a powerful React pattern for building flexible, expressive component APIs. Learn how to build components like Select, Tabs, and Accordion that feel native.