
Web Components: Shipping a Cross-Framework Library
A web-component library ships one implementation across React, Vue, Svelte, and plain HTML. A field guide to the surfaces you engineer and the limits of the approach.
TL;DR: A web-component library is a standards-based way to ship one component implementation that renders inside React, Vue, Svelte, and plain HTML alike — but it is a distribution craft with its own surfaces to engineer: element lifecycle, shadow-DOM styling, server rendering, form participation, framework interop, packaging, and versioning. This guide maps those surfaces, frames the public-contract mindset that runs through all of them, and states plainly where a component library earns its place and where it does not. Whether web components are the right choice at all is a separate evaluation; here we assume that decision is already made and cover the how.
A distribution problem, not a framework choice
The case for web components is not that they are a nicer way to build a component. It is that one component has to live in more than one place. A design system that a React application, a Vue admin panel, and a plain-HTML marketing page all consume. A set of widgets that independently deployed teams compose at runtime without agreeing on a framework first. An embeddable form or chat widget that must keep working after its host page is rewritten in whatever comes next. In every one of these cases the problem is distribution — one implementation, many consumers you do not control — and web components are the platform's answer to exactly that problem.
State the counter-case just as plainly, because it is the honest half. When every consumer of a component is unified on a single framework, that framework's own component model wins. It has better ergonomics, better types, better tooling, and none of the shadow-boundary friction this topic spends its pages managing. Reaching for web components inside a single-framework product adds cost without buying the portability that justifies the cost. The craft within this topic is worth learning precisely because it is not a default — it is the right tool for a specific and recurring situation.
There is a prior question this guide deliberately does not answer: are web components production-ready, and should this project choose them at all? That is a status check — an evaluation of platform maturity, browser support, and fit — and it lives in the web-compatibility literature as its own single, comprehensive treatment. This guide begins one step later, with the decision made, and concerns itself entirely with building and shipping the library well.
The surface inventory in one view
A component library is not one skill but eleven small ones, and the fastest way to lose a lot of time is to discover them one crisis at a time. The table below is the whole territory at a glance. Each row names a surface you will engineer, the decision it forces, and the article that owns its depth; the two foundations — a correctly behaving element and a deliberate styling strategy — sit under everything else.
| Surface | What it decides | Depth lives in |
|---|---|---|
| Element lifecycle | How the element registers, upgrades, reacts to attributes, and cleans up | The custom-element-lifecycle foundation |
| Shadow-DOM styling | What is encapsulated and which styling seams you open | The shadow-DOM-styling foundation |
| Declarative shadow DOM | How the component renders on the server before script runs | The server-rendering article |
| Form participation | Whether the element is a real form field or a hidden-input hack | The form-associated-elements article |
| Framework interop | How the element presents to React, Vue, Svelte, and Angular consumers | The framework-interop article |
| Public API design | Which attributes, properties, events, and slots are the contract | The API-design article |
| Packaging | How the library is bundled, published, and tree-shaken | The packaging article |
| Versioning | How the named surface evolves without breaking consumers | The versioning article |
| Accessibility | How semantics and focus survive the shadow boundary | The accessibility article |
| Theming | How consumers safely restyle what encapsulation hides | The theming article |
| Testing | How the library is exercised in a real DOM and kept honest | The testing article |
The map is worth reading before any single row, because the surfaces interlock. A styling decision constrains theming; an API decision sets up versioning; a lifecycle bug surfaces as symptoms in every other row. Treating the library as a collection of independent problems is the mistake this inventory exists to prevent.
What holds it together: the public-contract mindset
The single idea that makes a distributed component library coherent is that everything nameable on your element is a public API. An attribute, a property, an event name, a slot, a CSS part, a custom property — each one is a promise that some consumer, on a schedule you do not control, will come to depend on. A component you own inside your own application can be refactored freely. A component you publish cannot, because the refactor lands in someone else's build.
That mindset produces a recurring tension this whole topic keeps returning to: encapsulation versus customization. The shadow boundary that keeps the host page's selectors from matching the elements inside your component is the same boundary that stops a consumer from targeting those internals when they legitimately need to restyle them; inherited properties and custom properties set on the host still flow in. Every styling seam you open — a custom property your internal styles read, an exposed part — is a deliberate hole punched in the encapsulation you just built, and it becomes permanent API the moment you ship it. Designing that surface small and on purpose, rather than discovering it by consumer complaint, is what separates a library that ages well from one that becomes a support burden.
The framework-interop reality
The value proposition of a cross-framework component is only as good as how cleanly it presents to each framework, and here the honest picture has one persistent seam and one moving part. The persistent seam is that frameworks bind data and listen to events differently than the raw DOM does; passing a rich object property and listening to a custom event are the two friction points to check for each framework consumer.
The moving part is framework support itself. Since React 19, the most widely used frontend framework in the 2025 Stack Overflow Developer Survey assigns props to custom elements as DOM properties during client rendering when the element instance has a matching property, and as attributes otherwise; during server rendering it renders primitive values such as strings and numbers, and the value true, as attributes, and omits non-primitive values such as objects, symbols, and functions, and the value false. Earlier versions treated unrecognized props as attributes rather than properties and needed a thin wrapper to map props to properties (as of Nov 2026; re-verify against the framework's own documentation, since this is a support surface that moves). The interop article covers the property-versus-attribute mechanics, the event conventions, and the generated typings in depth. The point at this altitude is only that interop is a real cost with a real payoff, not a free lunch — and that naming a framework here means naming market reality, never ranking one against another.
How the work decomposes across this topic
This guide is the routing frame; the depth lives in the articles around it, and it helps to see the whole decomposition before diving into any one piece.
Two foundations sit under everything. The element-lifecycle foundation answers "how does this element behave correctly when the browser, not a framework, controls its life," and the shadow-DOM-styling foundation answers "what is encapsulated and what styling do I deliberately expose." Every other article assumes both. From there this topic works outward through declarative shadow DOM for server rendering, form-associated elements for real inputs, framework interop for the consumer side, public API design for the contract, packaging and publishing for distribution, versioning for evolution, accessibility for the shadow-specific semantics work, theming for safe customization, and testing for keeping all of it honest.
Two boundaries are worth stating once so they do not blur. Icon components have their own distribution craft — sizing, sprite strategy, the accessibility of a graphic — and that belongs to the SVG-and-icon-systems literature, not here; this topic is about general components. And the architecture of design tokens — their naming, their tiers, the pipeline that produces them — belongs to the design-tokens literature; theming within this topic is only the web-component mechanism that consumes and exposes those tokens, never the token system itself.
What a component library does not solve
A guide that only listed capabilities would be selling something, so the limits get their own section.
A component library is not a reason to adopt web components when your consumers are unified on one framework — the portability you are paying for has no one to serve. A closed shadow root is not a strong security mechanism, either: closing a root makes element.shadowRoot return null, but code that keeps the value returned by attachShadow() can still reach the root, and MDN notes that there are ways closed mode can be evaded, for example by browser extensions running in the page — so treating it as isolation invites a false sense of safety. And publishing a component does not remove the maintenance burden it creates — a change to a distributed API can ripple to every consumer, which is exactly why versioning is an article of its own rather than an afterthought.
One last honesty concerns the horizon. Several of the most interesting surfaces here are recent or still unsettled (as of Nov 2026, web-features): scoped custom-element registries, which let custom elements with the same tag name coexist in separate registries, became Baseline Newly available on October 27, 2026; declarative custom elements were described in the Web Components Community Group's 2022 report as a strawperson proposal that depended on many other proposals not yet finished; and cross-root ARIA would let references reach elements across shadow boundaries, while the related reference target feature, which forwards attributes such as for and aria-labelledby to elements inside a shadow root, is supported only in Chrome and Edge. This guide names them as horizon, with an as-of caption and a note to re-verify at the time of building, and never leans a load-bearing decision on a surface that has not settled (check the current status of each proposal before depending on it). The core of a web-component library — autonomous custom elements, shadow DOM, and HTML templates, loaded as JavaScript modules — has been Baseline Widely available for years (as of Nov 2026, web-features); customized built-in elements (the is attribute) are not Baseline, because web-features lists no Safari support for them. The frontier is where the caution belongs.