What is the difference between web components and React?
React is a JavaScript library for building apps, and its components only run inside React. Web components are your own HTML tags, built by the browser. Here is how the two differ in code, styles, and data, and why many teams use both.

Think of a phone and a charging cable. The phone runs your apps, and its maker decides how everything inside it works. The cable runs nothing at all, but it plugs into devices from many makers. Asking which one is better misses the point. They do different jobs, and they're made to work together.
React and web components are a lot like that.
React is a JavaScript library for building user interfaces, and its components only run inside React. Web components are HTML tags you define yourself with browser standards, and they work in any page and any framework, React included. Use React, or another framework, to run an app. Use web components for parts that many apps, frameworks, or teams share. Many projects use both.
What is each one?
React is a library. You write components: JavaScript functions that return a description of what should be on the screen, usually written in JSX. A React component's name starts with a capital letter, and React decides when to call it. The same model reaches beyond the browser: react-dom renders to web pages, and React Native to phone apps. Why React? explains what it's for.
Web components aren't a library. They're a name for three browser standards: custom elements (your own tags, each backed by a class), shadow DOM (a private inside for an element), and templates and slots (reusable markup, and holes the page fills in). Browsers build these tags themselves, so there's nothing to install. What are web components? introduces all three.
How do they look in code?
Here's a small label for a tea menu as a React component:
function TeaLabel({ name, minutes }) {
return <p>{name}: brew for {minutes} minutes</p>;
}
export default function Menu() {
return <TeaLabel name="Green tea" minutes={3} />;
}
And here's the same label as a web component:
class TeaLabel extends HTMLElement {
connectedCallback() {
const name = this.getAttribute("name");
const minutes = this.getAttribute("minutes");
this.textContent = `${name}: brew for ${minutes} minutes`;
}
}
customElements.define("tea-label", TeaLabel);
<tea-label name="Green tea" minutes="3"></tea-label>
The React version is a function, and only React can use <TeaLabel>. The web component is a class that extends HTMLElement. customElements.define() tells the browser to build every <tea-label> tag with it, on any page. Its name must contain a hyphen, so it can never clash with a tag HTML adds later. Your first custom element walks through each line.
Look at minutes too. In React, minutes={3} passes the number 3. In HTML, an attribute is always text, so the web component gets the string "3".
How are they different?
| React component | Web component | |
|---|---|---|
| What it is | A function that returns a description of the UI | A class that extends HTMLElement, registered as a tag |
| Its name | Starts with a capital: TeaLabel |
Has a hyphen: tea-label |
| Where it runs | Inside a React app | Any page and any framework, or none |
| Data in | Props, of any type | Attributes (always text) and properties (any value) |
| News out | Functions passed down as props | DOM events, like a CustomEvent |
| Updating the screen | React renders again and changes only what differs | Your code updates the DOM, or a library like Lit does |
| Styles | Global CSS, or CSS Modules to scope class names | Shadow DOM keeps styles inside the component |
| Setup and cleanup | Effects | connectedCallback() and disconnectedCallback() |
| What you load | The React library | Nothing, because browsers build them |

How does each one update the screen?
This is the biggest day-to-day difference.
In React, you keep data in state. When it changes, React calls your component again, compares the new description with the last one, and changes only the parts of the page that differ. How React works follows one click through those steps. You describe the screen, and React does the bookkeeping.
A web component has no built-in re-render. Your class changes the DOM itself. The quickest way, setting innerHTML again, rebuilds every node, so typed text and focus are lost. The better way keeps a reference to each part that changes and updates only those. Ways to render a component compares the options. Lit, a small library for writing web components, does that bookkeeping for you.
How do they handle styles?
CSS is global in React: a .title rule matches every .title on the page. CSS Modules fix that by giving each class a unique name when you build.
Web components can use shadow DOM instead. A shadow root is a private tree attached to the element. The page's CSS rules don't reach inside, and the component's rules don't leak out. Inherited styles, like the text color and font, still pass in. So do custom properties, which is how a component lets the page theme it. Shadow DOM is optional, though. An HTML web component skips it and adds behavior to the page's own HTML.
Can you use web components in React?
Yes. React 19 supports custom elements fully. Here's a star rating web component inside a React component:
import { useState } from "react";
import "./tea-rating.js";
export default function Review() {
const [stars, setStars] = useState(4);
return (
<tea-rating value={stars} onrating-change={(event) => setStars(event.detail)} />
);
}
Importing tea-rating.js runs its define() line. Before setting a prop, React 19 checks whether the element has a property with that name. If it does, React sets the property, so objects and arrays arrive whole. If not, React sets an attribute. To listen for a custom event, write on followed by the event's exact name, here onrating-change. Older versions of React set only attributes, which is why web components once felt awkward there.
One catch: load the component's file before React renders the tag. Until the class is defined, the element has no properties, so React falls back to an attribute, and an object becomes the text [object Object]. A preview of web components in frameworks shows this happening, and how Vue, Angular, and Svelte handle the same tag.
Which one should you use?
Ask who will use the part.
- One app owns it: build it in that app's framework. A checkout flow, a settings screen, or a dashboard lives in one app, and React's state and re-rendering make it simpler.
- Many apps or frameworks share it: make it a web component. A design system's buttons, a widget other sites paste in, or a rating used across a React shop and a plain HTML blog all fit.
- HTML already has it: use the built-in element. A tag named
tea-buttongets no keyboard support or button role from its name, so a real<button>wins.
That's why the two often sit together. A team builds its app in React and its shared design system as web components. React runs the app, and each web component is one more tag inside it. When to use web components, and when not weighs the arguments on both sides.
If you're choosing what to learn, they don't compete. Both stand on the same JavaScript and DOM, so time spent on one makes the other easier.
Where to go next
Start the web components tutorial to build your own tags from scratch, beginning with what web components are. If you're building apps, the React course takes you from your first component to how React renders under the hood.


