October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

React Portals Explained: How They Work and When to Use Them

React portals place content elsewhere in the DOM while keeping it in the React tree. Learn how they help with clipping, how their events bubble, and what modal accessibility requires.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

React portals render content in a different part of the DOM without moving it out of the React tree. That makes them useful when a modal, tooltip, or similar element needs to escape an ancestor’s clipping or styling constraints—but portals do not handle positioning, event behavior, or accessibility for you.

How React portals work

createPortal(children, domNode, key?) returns a React node that renders its children inside the specified DOM node. That destination node must already exist. If it changes during an update, React recreates the portal content.

As an Amazon Associate I earn from qualifying purchases.

The key distinction is that a portal changes physical DOM placement, not React ownership. A portaled component remains part of its original React tree, so it can still read context from its React ancestors. As React puts it, “A portal only changes the physical placement of the DOM node.” React’s createPortal reference documents the API and its behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a portal helps

Use a portal when an element needs to appear outside the visual or layout constraints of one of its DOM ancestors. For example, a modal placed inside a container styled with overflow: hidden may be clipped; rendering it elsewhere in the DOM can avoid that constraint. Tooltips and popups can face similar ancestor-style problems.

A portal is only a placement mechanism. Your implementation still needs to determine the element’s position, stacking order, visibility, and interaction behavior. React also documents rendering into a popup DOM node supplied by a third-party widget: keep that node and render into it once it exists. See React’s portal guidance.

How portal events behave

Events from a portal bubble according to the React tree, not the physical DOM tree. Consequently, clicking inside a portal can trigger a React onClick handler on an ancestor component even when that ancestor is nowhere above the portal in the DOM.

If that behavior is unwanted, stop propagation inside the portal or move the portal higher in the React tree. When debugging an unexpected click, inspect the React ancestry as well as the DOM structure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What to implement for an accessible modal

Rendering a dialog through a portal does not make it accessible. The WAI-ARIA Authoring Practices Guide modal pattern describes the interaction and semantics a modal needs. In particular, content outside the active modal should be inert: users should not be able to interact with it while the dialog is open.

  • Give the dialog an accessible name. Use aria-labelledby referencing a visible title, or provide an aria-label.
  • Move focus into the dialog on opening. For long or structurally complex content, consider initially focusing a static element near the beginning.
  • Keep keyboard focus within the dialog. Tab and Shift+Tab should navigate among its controls without moving focus into inactive outside content.
  • Support Escape to close when that is appropriate for the dialog, and ordinarily return focus to the element that opened it when it closes.
  • Provide a visible close button in the dialog’s tab sequence.

For long or complex dialog content, the APG generally advises omitting aria-describedby when it would cause the content to be announced as one unbroken description rather than preserving its structure.

When to use aria-modal=”true”

Set aria-modal="true" only when the dialog really behaves as modal: it visually obscures the background and the application prevents interaction with outside content. The attribute does not create those behaviors. Marking a dialog modal while leaving the background interactive can mislead assistive-technology users about what they can perceive or operate.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Decide whether a portal is the right tool

Choose based on the constraint you need to solve, not on the assumption that every overlay belongs in a portal. Check whether a DOM ancestor clips or otherwise constrains the content, whether React-tree event bubbling will affect existing handlers, and what focus and keyboard behavior the overlay requires. For a modal, also confirm that the background is genuinely inert. The React and WAI-ARIA guidance does not establish portals as universally preferable; the right choice depends on the layout and interaction requirements.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.