Browser Basics Behind React
Shadow DOM and React
Know what Shadow DOM is and why it is different from normal React components.
8 minutes - Absolute beginner
What this means
Shadow DOM is a browser feature that lets an element hide its internal DOM and styles from the rest of the page. It is often used by Web Components.
In beginner terms, this topic answers one practical question: "What should I write, and why does React care about it?" Do not try to memorize the syntax first. First understand the idea, then connect the syntax to that idea.
Why it matters
React components are not Shadow DOM by default. A React component organizes code, but its rendered elements usually become part of the normal DOM tree unless you intentionally render into a shadow root.
When you build real React screens, this idea helps you decide where data should live, what the user should see, and what should happen after an interaction. That is why this lesson is part of the main path instead of being an optional detail.
Step by step
1. Notice the UI problem this topic solves. 2. Look at the smallest possible example. 3. Change one value and predict what should appear. 4. Run the example and compare the result with your prediction. 5. Use the practice task before moving on.
Small example
const shadowRoot = element.attachShadow({ mode: "open" });Common mistake
Do not assume a React component automatically isolates CSS like Shadow DOM. Normal React CSS can still affect or be affected by other page styles depending on how you write it.
Practice task
Explain the difference between a React component and a Web Component using Shadow DOM in two sentences.
Remember this
React components organize UI code; Shadow DOM isolates browser DOM and styles.
try.it
Examples
Try it: Shadow DOM and React
Edit this focused React example and run it in the browser preview.
Preview runs React in a sandboxed browser frame, never on the server.
editor
preview
Login to save progress
You can read lessons without an account, but progress requires login.