
Web Components: Custom Elements, Shadow DOM, Forms, SSR
Form-associated custom elements (Safari 16.4) and declarative Shadow DOM addressed two long-standing gaps for design systems. The use cases that justify Web Components, and the ones that do not.
TL;DR: All four foundational APIs — Custom Elements, Shadow DOM, HTML templates, and ES Modules — are Baseline Widely available. Two pieces that had made Web Components harder to adopt for design systems have now landed: form-associated custom elements (Safari 16.4, March 2023) make custom elements first-class form participants, and declarative Shadow DOM (cross-engine since Firefox 123 in February 2024, Baseline Widely available since August 2026) lets components render server-side without client JavaScript. React 19's improved property handling fixed the historical interop pain. Web Components fit specific jobs — design-system distribution and microfrontend integration — rather than serving as a default app architecture, and for those jobs they are now production-ready.
Where Web Components actually are in 2026
The platform readiness story is settled.
Custom Elements, Shadow DOM, HTML templates, and ES Modules — the four foundational APIs — are Baseline Widely available and have been for years. Form-associated custom elements (ElementInternals) shipped in Safari 16.4 in March 2023, reaching cross-engine availability and giving design-system form components a native way to take part in forms; before that, custom form controls relied on workarounds such as hidden inputs. Declarative Shadow DOM became available across engines when Firefox 123 shipped it in February 2024, after Chrome 111 and Safari 16.4 in 2023, and as of October 2026 it is Baseline Widely available (since August 2026, per the web-features data); Web Components no longer require client-side JavaScript to render their structure, which is the precondition for SSR-first frameworks adopting them.
Framework interop has stabilized. On the client, React 19 sets a prop on a custom element as a DOM property when the element instance has a property with that name (otherwise it still sets an attribute), which addresses the historical interop pain that limited Web Components in React projects. Vue 3, Svelte, Solid, and Preact already pass the Custom Elements Everywhere test suite; React was the notable exception, and React 19 now passes it too.
Despite the platform readiness, Web Components fit specific jobs rather than every project. They suit design-system distribution across multiple framework consumers and microfrontend integration where independently deployed teams need to compose at runtime. They are not the right choice as a default app architecture when all consumers are on the same framework — the framework's own component model is usually simpler to author and better integrated with the framework's tooling.
The 2026 question is no longer "are Web Components production-ready" — they are. The question is "is Web Components the right tool for this distribution problem," which depends on the organizational context, not on the platform.
Custom Elements API
Custom Elements register a new HTML tag tied to a JavaScript class:
class TabsList extends HTMLElement {
static observedAttributes = ['orientation'];
connectedCallback() {
this.setAttribute('role', 'tablist');
this.addEventListener('click', this.#onClick);
}
disconnectedCallback() {
this.removeEventListener('click', this.#onClick);
}
attributeChangedCallback(name, oldValue, newValue) {
if (name === 'orientation') {
this.setAttribute('aria-orientation', newValue);
}
}
#onClick = (event) => {
// tab click handling
};
}
customElements.define('tabs-list', TabsList);The lifecycle callbacks are the integration points with the DOM. connectedCallback runs when the element is inserted into a document; disconnectedCallback runs when it is removed. attributeChangedCallback runs when an observed attribute changes — the static observedAttributes array declares which attributes trigger it. adoptedCallback runs when the element moves to a new document — for example via document.adoptNode() into an iframe's document.
The element class extends HTMLElement for the autonomous-custom-element form (the tag is a new tag — <tabs-list>). This form is Baseline Widely available (since July 2022, per web-features; as of Nov 2026).
The customized-built-in-element form (extending an existing element class with the is= attribute) is supported in Chromium and Firefox but not Safari. The WebKit team said in 2016 that it would not implement customized built-ins, and WebKit's standards position is 'oppose' (as of Nov 2026 — an opinion on the specification, not an implementation status), so customized built-ins should be treated as non-Baseline. If you need a custom button that behaves like a <button>, ship an autonomous custom element with the right ARIA role rather than an is="my-button" extending HTMLButtonElement.
Shadow DOM — open, closed, and slot composition
Shadow DOM creates an encapsulated DOM subtree that is isolated from the document's main DOM:
class CardElement extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: 'open' });
shadow.innerHTML = `
<style>
:host { display: block; padding: var(--card-padding, 1rem); }
.body { color: var(--card-text); }
</style>
<div class="body"><slot></slot></div>
`;
}
}
customElements.define('iro-card', CardElement);attachShadow({ mode: 'open' }) creates a shadow root accessible via element.shadowRoot. mode: 'closed' hides the shadow root from external JavaScript — element.shadowRoot returns null. Closed mode has real costs: it makes debugging harder, and it is not a strong security mechanism (anyone with access to the page can still observe the rendered DOM). Default to open unless there is a specific reason to hide.
Style encapsulation is the load-bearing feature. CSS inside the shadow root does not leak out; document styles do not leak in. The exceptions are intentional: inheritable properties (color, font, line-height) inherit through the shadow boundary, and CSS custom properties cross the boundary so design tokens propagate naturally:
/* Document stylesheet */
:root {
--card-padding: 1.5rem;
--card-text: oklch(20% 0 0);
}/* Inside the shadow root */
:host { padding: var(--card-padding); }
.body { color: var(--card-text); }The card inherits the design tokens without explicit threading; descendants of the card can also read them.
Slot composition projects light-DOM children into the shadow tree:
<iro-card>
<h2 slot="header">Title</h2>
<p>Body content</p>
</iro-card><!-- inside the shadow root -->
<header><slot name="header"></slot></header>
<div class="body"><slot></slot></div>The <slot name="header"> projects elements with slot="header"; the unnamed <slot> projects children that have no slot attribute (a child whose slot value matches no slot is not projected). The light-DOM children remain in the document tree (and are styled by document CSS), but their rendered position is determined by the shadow tree.
External styling control is limited but available. ::part() lets a component expose specific internal elements for external styling:
<!-- inside iro-button's shadow root -->
<button part="trigger"><slot></slot></button>iro-button::part(trigger) {
background: var(--brand);
}::slotted() styles elements projected into a slot:
/* Inside the shadow root */
::slotted(h2) {
font-family: var(--font-heading);
}Both are limited compared to direct CSS — ::part() only addresses the named element, ::slotted() only addresses immediate children — but they are sufficient for theming the parts the component exposes.
Declarative Shadow DOM for SSR
The historical SSR limitation was that Shadow DOM had to be created with JavaScript — element.attachShadow() — which meant a server-rendered page could not include shadow content until after script execution. Declarative Shadow DOM lets you declare the shadow root in HTML:
<iro-card>
<template shadowrootmode="open">
<style>
:host { display: block; padding: 1rem; }
</style>
<div class="body"><slot></slot></div>
</template>
<h2>Title</h2>
<p>Body content</p>
</iro-card>The browser parses the <template shadowrootmode="open"> element, attaches the shadow root, and the component is rendered before any script executes. SSR frameworks can output the full component tree as HTML, and the browser displays it correctly without hydration.
This became cross-engine in February 2024 and has been Baseline Widely available since August 2026. As of October 2026, the tools that server-render Web Components as declarative Shadow DOM include Lit SSR (still a Lit Labs experimental package); Enhance also server-renders custom elements as HTML. Astro can emit declarative Shadow DOM markup in its HTML, but Astro 5 removed the official @astrojs/lit integration, so server-rendering Lit components in Astro is no longer officially supported; Astro's upgrade guide suggests maintaining the integration yourself from its last published version. WC Toolkit is useful alongside these — it is a set of tools built around the Custom Elements Manifest (utilities that read and extend the manifest and add TypeScript type data to it). For frameworks without native support, the polyfill pattern (parsing the page after load and converting <template shadowrootmode> elements to shadow roots) was always small and is rarely needed now that declarative Shadow DOM is Baseline Widely available, unless your support policy includes browsers older than Chrome 111, Firefox 123, or Safari 16.4.
The combination of declarative Shadow DOM and form-associated custom elements turned Web Components into a viable SSR-first design system distribution format. The two pieces together removed blockers that had kept some teams from adopting Web Components even when they wanted to.
Form-associated custom elements
This is the API that turned Web Components into first-class form components.
class IroSelect extends HTMLElement {
static formAssociated = true;
#internals;
#value = '';
constructor() {
super();
this.#internals = this.attachInternals();
}
connectedCallback() {
this.tabIndex = 0;
// ... set up the select UI in shadow DOM ...
}
set value(newValue) {
this.#value = newValue;
this.#internals.setFormValue(newValue);
this.dispatchEvent(new Event('change'));
}
get value() {
return this.#value;
}
checkValidity() {
return this.#internals.checkValidity();
}
reportValidity() {
return this.#internals.reportValidity();
}
}
customElements.define('iro-select', IroSelect);static formAssociated = true opts the element into form participation. this.attachInternals() returns an ElementInternals object — the API for setting form value, validity state, and validation message.
this.#internals.setFormValue('value') sets the value the form will submit. ElementInternals has no value property to read back, so the component keeps its own copy (the private #value field) for the value getter and reports it to the form with setFormValue(). The element now appears in FormData and in the submit event the same way a native input would. A <form> containing <iro-select name="country"> submits with country=... like any other field.
Validity participation uses setValidity:
set value(newValue) {
this.#value = newValue;
this.#internals.setFormValue(newValue);
if (this.hasAttribute('required') && !newValue) {
this.#internals.setValidity({ valueMissing: true }, 'Please select a country');
} else {
this.#internals.setValidity({});
}
}The element participates in form.checkValidity(), form.reportValidity(), the :invalid pseudo-class, and constraint validation alongside native inputs.
Labels and accessibility wiring are also handled through ElementInternals:
constructor() {
super();
this.#internals = this.attachInternals();
this.#internals.role = 'combobox';
this.#internals.ariaLabel = 'Country';
}
get labels() {
return this.#internals.labels;
}ElementInternals.labels returns the <label> elements that reference this element — the same for= / id= pattern that works for native inputs works for form-associated custom elements. ElementInternals.role and the ARIA reflection properties (ariaLabel, ariaExpanded, etc.) set default ARIA semantics for the element, which the page can still override with role and aria-* attributes.
This was the missing piece for form components. Before Safari 16.4 (March 2023), Web Components could not be true form fields in every major engine, so design-system inputs like custom select, custom date picker, custom checkbox group had to rely on workarounds such as hidden inputs to be shipped as Web Components. Safari 16.4 in March 2023 was the last engine to ship form-associated custom elements; from that date forward, design systems can ship form components as Web Components and have them participate in HTML forms correctly.
Framework interop in 2026
The framework integration story is finally good across the board.
On the client, React 19 (stable December 2024) assigns a prop to a custom element as a DOM property when the element instance has a property with that name, rather than as a stringified attribute; props with no matching property are still set as attributes. During server rendering, React 19 still omits non-primitive props, so they arrive only after hydration. The historical pain was that React would set <my-component complexProp={obj}> as an attribute (complexProp="[object Object]"), and the custom element would have to read the attribute and parse it. With React 19, if the element defines a complexProp property, the value is set directly on the element instance, and the custom element reads this.complexProp as the actual object.
For React 18 and earlier, the workaround is to wrap the custom element in a thin React wrapper that maps props to properties manually, or to use the @lit/react helper that does the wrapping automatically for Lit components. The wrapper pattern is well-understood; a common approach is to ship React wrappers as a separate npm package alongside the Web Component package.
Vue 3, Svelte, Solid, and Preact all pass the Custom Elements Everywhere tests, though Vue and Solid sometimes need explicit property-binding syntax. The same custom-element distribution works across all four without per-framework wrappers.
Server-rendered apps (Next.js, React Router v7 in framework mode — the successor to Remix, which merged into React Router — Astro, SvelteKit) can include Web Components; rendering a component's shadow root to declarative Shadow DOM is a separate step, handled by a component-level SSR tool such as Lit SSR or by hand-written <template shadowrootmode> markup. When the shadow root is in the HTML, the browser displays it before script execution and only the interactive parts need to load JavaScript.
Bundling distributes design-system Web Components as ES Modules with a separate entry per component. A typical package layout:
@my-design-system/components/
├── button.js (one entry per component)
├── card.js
├── input.js
├── index.js (re-exports all)
└── package.json (with "exports" field)Consumers import only what they need: import '@my-design-system/components/button.js'. Unused components stay out of the bundle because they are never imported: each component module registers its element with customElements.define() when it is imported, which is a side effect, so a bundler keeps every component module that is imported, and importing index.js brings in every component it re-exports. This holds only while the package does not mark its component modules as side-effect-free in the sideEffects field of package.json; webpack, for example, can drop a module marked that way even when it was imported only to register the element.
Use cases that justify Web Components
The use cases where Web Components are the right answer are specific.
Design-system distribution across multiple framework consumers — one component implementation, used by React, Vue, plain-HTML, and SSR consumers. The marginal cost of supporting one more framework can be lower than maintaining parallel React + Vue implementations. This is where the cross-framework advantage applies directly.
Microfrontends with independently deployed teams — components that compose at runtime without a shared framework. The host page does not need to bundle a specific framework version; teams ship components that drop into any host. The trade-off is that the host page has to be designed for runtime composition, which is its own architectural commitment.
Long-lived embeds that need to survive a host page's framework rewrite — analytics widgets, embeddable forms, chat widgets. The widget ships as a Web Component, the host page can swap React for Vue for plain HTML over the years, and the widget keeps working. Embeds whose lifecycle is longer than the host's framework lifecycle benefit from Web Components.
Headless CMS preview rendering — server-rendered components that work in the editor's iframe without a framework boot. The CMS does not need to know your framework; the components render as HTML.
When all consumers are on the same framework, Web Components add complexity without benefit. Use the framework's component model. The Web Components advantage is cross-framework portability; if you do not need that portability, you do not need Web Components.
Common pitfalls
Five mistakes appear in code review.
Forgetting that style encapsulation breaks for global form-control styling — buttons inside a shadow root do not inherit body button styles. The fix is to expose tokens via CSS custom properties and read them inside the component, not to leak global styles through the shadow boundary.
Using customized built-in elements (extends HTMLButtonElement, is="my-button") and assuming Safari support — Safari does not support them; the WebKit team said in 2016 that it would not implement them, and WebKit's standards position is 'oppose' (as of Nov 2026). Use autonomous custom elements (extends HTMLElement, <my-button>) and replicate the button semantics with ARIA and tabindex.
Treating closed shadow roots as a security boundary — they are not a strong security mechanism. They are an encapsulation hint that hides the shadow root from external scripts on the same page; they do not prevent an attacker who already runs JavaScript on the page from observing the rendered DOM. Real isolation requires same-origin policy and <iframe> boundaries, not shadow root mode.
Over-relying on slot composition for complex layout — slots are positional, not flexible like framework children with named props. A component that needs to render different child compositions in different states is better expressed with attributes that the component reads, not with slot proliferation.
Skipping the form-associated path for custom inputs — the pre-2023 fallback patterns (hidden inputs, manual form-data assembly) are no longer necessary in 2026. New custom inputs should use formAssociated = true and attachInternals() from the start.
Evaluation criteria for the next planning cycle
- If your design system is consumed by multiple frameworks, evaluate Web Components as a single-implementation distribution format; measure the maintenance cost vs the per-framework parallel-implementation cost
- If you are starting a new design system that will only have one framework consumer, do not use Web Components — use the framework's component model
- If you ship form components as Web Components, use form-associated custom elements with
attachInternals()andsetFormValue()— do not use the pre-2023 hidden-input workaround - For SSR-first frameworks, pair Web Components with declarative Shadow DOM (
<template shadowrootmode="open">) so components render server-side without client JavaScript - If you have React consumers on React 18 or earlier, ship a thin React wrapper alongside the Web Component package; React 19 consumers can use the components directly
- Document the design tokens that cross the shadow boundary (CSS custom properties) and the parts that expose styling control (
::part()) — without documentation, consumers cannot theme the components reliably