All WordPress HTML Templates Forms & Webhooks AI & Tools
HTML Templates

Web Components vs Framework Components: A Sober Comparison

Web components vs framework components, judged on real client builds: when custom elements win, when shadow DOM costs more than it’s worth, and the ARIA

A real working moment illustrating the theme of an article about web components. Wide 16:9 banner, one strong focal point, magazine editorial quality, authentic and unstaged.

We inherited a design system last year that shipped 60 components as custom elements with shadow DOM. Tech-agnostic, future-proof, framework-free: the pitch was correct on paper. Then the client’s marketing team tried to drop a Bootstrap utility class on a button inside one of them and nothing happened, their analytics vendor’s click tracking stopped resolving selectors, and the “accessible” combobox couldn’t point aria-activedescendant at its own listbox because the ID lived on the other side of a shadow boundary.

None of that means web components were the wrong call. It means the team bought the platform’s strongest feature (custom elements) and its most expensive feature (shadow DOM) as a single bundle, which is how most of these projects go sideways.

Here’s the version of this comparison we’d give you over a coffee, after shipping both.

Key Takeaways

  • Custom elements and shadow DOM are separate decisions. Light DOM custom elements give you lifecycle, encapsulated behaviour and zero-build portability while keeping global CSS, querySelector and ARIA references working.
  • Shadow DOM earns its keep for third-party widgets and multi-tenant embeds where style collision is a real risk. Inside your own app it mostly buys you a CSS scoping problem you could have solved with a BEM prefix or @scope.
  • Cross-root ARIA is still the hard blocker in 2026. Anything needing aria-activedescendant, aria-controls or aria-labelledby across the boundary (comboboxes, tabs, tree views) is fragile until Reference Target ships everywhere.
  • React 19 finally sets properties rather than stringifying everything onto attributes, so custom elements are usable in React without a wrapper layer. Vue needs isCustomElement, Angular needs CUSTOMELEMENTSSCHEMA.
  • Framework components still win on data flow, typed props, hot reload and SSR output. Web components win on lifespan: a 2017 custom element still runs, a 2017 class component build probably doesn’t.

What web components actually give you

Strip away the marketing and there are four real capabilities in the spec family, and they’re independently useful.

Custom elements give you a tag name bound to a class with lifecycle hooks (connectedCallback, disconnectedCallback, attributeChangedCallback) plus upgrade semantics: the browser will run your constructor on elements that were already in the HTML before your script loaded. That last part is the quiet superpower. It’s the only component model that works on server-rendered HTML with no hydration protocol and no framework runtime.

Shadow DOM gives you style and markup encapsulation plus slot-based composition. Templates give you inert markup, now mostly obsoleted by better tooling except for declarative shadow roots. ElementInternals gives you form participation and a native-ish accessibility surface.

Most of the value in day-to-day client work sits in the first and the last. Here’s a component we actually ship, pattern unchanged across about a dozen sites, with no shadow DOM at all:

<char-counter max="280">
  <label for="bio">Short bio</label>
  <textarea id="bio" name="bio"></textarea>
  <p class="small text-muted" data-count>0 / 280</p>
</char-counter>
class CharCounter extends HTMLElement {
  connectedCallback() {
    this.field = this.querySelector('textarea, input');
    this.output = this.querySelector('[data-count]');
    // The markup is the contract. If it is missing, do nothing and leave a working form behind.
    if (!this.field || !this.output) return;
    this.max = Number(this.getAttribute('max')) || 0;
    this.field.addEventListener('input', this.update);
    this.update();
  }

  disconnectedCallback() {
    this.field?.removeEventListener('input', this.update);
  }

  update = () => {
    const len = this.field.value.length;
    this.output.textContent = ${len} / ${this.max};
    this.toggleAttribute('data-over', this.max > 0 && len > this.max);
  };
}
customElements.define('char-counter', CharCounter);

Delete the JavaScript and you still have a labelled textarea that submits. That’s a progressive enhancement story no framework component gives you for free, and it’s why this style (the one people now call HTML web components) has quietly become the default for content sites and WordPress themes rather than the full shadow DOM approach.

A real working moment that fits an article section about

Shadow DOM is the real decision, not custom elements

Adopting custom elements costs you almost nothing. Adopting shadow DOM costs you your global stylesheet, your utility classes, your third-party scripts’ selectors, and your ability to reference IDs across the boundary. You get encapsulation in exchange. Decide whether you’re actually being paid for that trade.

Where it’s clearly worth it:

  • Embeddable widgets dropped into pages you do not control (chat bubbles, booking forms, review widgets). The host page’s * { box-sizing: content-box } cannot reach you.
  • Multi-tenant platforms where client CSS is user input.
  • Components distributed to teams on different frameworks and different design systems.

Where it usually isn’t: your own marketing site, your own app, your own theme. If you’re already building on something like Canvas with Bootstrap 5 utilities and a token layer, putting a shadow root around a card means reimplementing spacing, typography and colour inside every component. We’ve watched teams spend a sprint rebuilding what @scope and a two-letter class prefix would have handled.

If you do use it, pierce the boundary deliberately rather than by accident. Custom properties inherit through shadow roots, so a token-driven theme still works, which is exactly the approach described in dark mode done properly. Expose structural hooks with part and nothing else:

<ui-card>
  <template shadowrootmode="open">
    <style>
      :host { display: block; border: 1px solid var(--card-border, #e5e7eb); border-radius: .5rem; }
      .body { padding: var(--card-pad, 1rem); }
    </style>
    <div class="body" part="body"><slot></slot></div>
  </template>
  <h3>Server-rendered heading</h3>
  <p>Light DOM content: crawlable, selectable, styleable from the page.</p>
</ui-card>
/ The only sanctioned third-party override. Everything else stays internal. /
ui-card::part(body) { padding-block: 1.5rem; }

That shadowrootmode="open" template is declarative shadow DOM, supported across Chromium, Firefox and Safari since 2024. It’s what made shadow DOM viable for server-rendered pages: the shadow root exists in the initial HTML before any script runs, so you don’t get a frame of unstyled slot content.

Where framework components still win, plainly

Anyone telling you the platform has caught up with React or Vue for application UI is selling something. The gaps are specific.

Data flow. Attributes are strings. Passing an object means setting a property imperatively or JSON-encoding it, and neither survives a template engine cleanly. Lit’s .prop= syntax fixes this inside Lit. Raw custom elements in raw HTML do not have an answer.

Rendering. You get no diffing, no keyed lists, no batching. Write the naive version and you’ll rebuild innerHTML on every state change. That reads fine in dev on a 200-row table and stutters on a mid-range Android in production. This is why Lit exists. At roughly 5 KB min+gzip for the core it’s a cheap fix, but now you have a framework. Just a small one.

SSR. Framework components render to HTML as a first-class feature. Custom element SSR means either declarative shadow DOM generated by hand, or Lit’s SSR package, which works but constrains how you write. Light DOM custom elements sidestep this entirely because your server template already produces the markup.

Tooling. Typed props, hot module replacement that preserves state, devtools that show a component tree. Custom element DX in 2026 is better than it was (custom-elements-manifest, editor autocomplete via the VS Code HTML custom data file) but it’s not close.

The accessibility problem nobody has finished solving

This is the one that should decide architecture, and it rarely gets mentioned in listicles. ID references do not cross shadow boundaries. If your combobox input lives in the shadow root and the consumer’s label lives in the light DOM, aria-labelledby silently resolves to nothing. Same for aria-controls, aria-describedby and aria-activedescendant.

Three partial answers exist today. ElementInternals lets you set roles and ARIA state on the host element, which covers simple cases. The Reference Target proposal (shadowrootreferencetarget) is the real fix and is landing in Chromium first, so it isn’t something you can rely on cross-browser for a production client build yet. And you can duplicate labels into the shadow root, which works and is also a maintenance liability.

Our rule: if a component’s accessible name or active state must be wired to something outside it, build it in the light DOM. That covers comboboxes, tab sets, tree views, custom listboxes, anything with a described relationship. The same logic is why we keep recommending you not build a carousel at all unless the brief genuinely demands one.

Form participation is the bright spot. This has shipped everywhere and it works:

class ToggleSwitch extends HTMLElement {
  static formAssociated = true;      // makes the element submittable
  #internals = this.attachInternals();

  connectedCallback() {
    this.#internals.role = 'switch';
    this.tabIndex = 0;
    this.#sync(this.hasAttribute('checked'));
    this.addEventListener('click', () => this.#sync(!this.checked));
  }

  get checked() { return this.hasAttribute('checked'); }

  #sync(on) {
    this.toggleAttribute('checked', on);
    this.#internals.ariaChecked = String(on);
    // Named value lands in FormData, so a plain POST or a WebForms endpoint just works.
    this.#internals.setFormValue(on ? (this.getAttribute('value') ?? 'on') : null);
  }
}
customElements.define('toggle-switch', ToggleSwitch);

Because the value goes into FormData, a custom element behaves like a native input for anything reading the form, including a no-backend endpoint like WebForms. That’s the kind of interop frameworks never gave you.

Interop in 2026: React, Vue, Angular

React was the long-standing excuse for avoiding custom elements and that excuse expired with React 19. It now sets properties when a property exists on the element and falls back to attributes otherwise, and it listens for custom events through on props rather than requiring addEventListener in an effect. Still on React 18? The wrapper-ref pattern is unavoidable, and that alone is a decent argument for the upgrade.

Vue needs the compiler told which tags to leave alone:

// vite.config.js
vue({
  template: {
    compilerOptions: {
      // Anything with a dash is a custom element, not a Vue component.
      isCustomElement: (tag) => tag.includes('-')
    }
  }
})

Angular needs CUSTOMELEMENTSSCHEMA in the module or component metadata. Svelte and Astro need nothing. Static site generators need nothing, which is the point: a custom element is the only component format you can hand to four teams on four stacks without writing four adapters.

One operational gotcha. Lazily loaded element definitions cause layout shift unless you hide undefined elements, and that shows up directly in LCP and CLS, the metrics worth actually chasing:

/ Reserve space, avoid a flash of unstyled custom element /
ui-card:not(:defined) { visibility: hidden; min-height: 8rem; display: block; }

How we decide, in order

  1. Is it one app, one team, one framework? Use framework components. The portability argument is hypothetical and you’ll pay for it daily.
  2. Does it need to work in HTML a CMS or a client produces? Light DOM custom elements. WordPress theme work, email-template-adjacent markup, docs sites.
  3. Does it ship into pages you don’t control? Shadow DOM, closed if you can, with a declarative shadow root for first paint.
  4. Does it need cross-boundary ARIA? Light DOM, no exceptions, until Reference Target is broadly available.
  5. Does it need to re-render lists or complex state? Lit, or a framework. Not hand-rolled innerHTML.

One more thing that changed the calculus: component-level responsiveness no longer requires JavaScript measuring. Container queries work identically in the light DOM and inside a shadow root, which removed one of the last real reasons to reach for a framework’s resize abstractions.

Frequently Asked Questions

Can I use custom elements without shadow DOM?

Yes, and for most projects you should. Skip attachShadow entirely and your component’s children stay in the light DOM, which means global CSS applies, document.querySelector finds them, and ARIA ID references resolve. You keep lifecycle callbacks, attribute observation and form participation, which is where the real value lives.

Are web components bad for SEO?

Light DOM content is indexed normally. Content inside a shadow root is flattened by Googlebot’s rendering, so it is usually seen, but it depends on your JavaScript running successfully on their crawl. Server-render your copy into the light DOM and slot it in; never generate primary text content in connectedCallback.

Do I still need Lit, or is vanilla enough?

Vanilla is enough for behaviour-only components: counters, toggles, lazy video embeds, scroll effects, disclosure widgets. Reach for Lit as soon as a component renders a list, has more than about three pieces of reactive state, or needs templating. The 5 KB is cheaper than the re-render bugs you’ll otherwise write.

How do I style inside someone else’s shadow DOM?

Only through what the author exposed: inherited custom properties, ::part() for named internals, and ::slotted() for content you passed in. If none of those exist, you cannot style it. Your only options are forking the component or asking the author. Treat the absence of parts and custom properties as a red flag when evaluating a component library.

Will web components replace React?

No, and that framing has wasted a lot of argument. They solve different problems: custom elements are a distribution and lifespan format, frameworks are an application architecture. The genuinely useful combination is a design system published as custom elements, consumed by whatever app framework each team picked.

The call

Pick your next component and ask one question: will anything outside this component need to style it, label it, or find it? If yes, build a light DOM custom element and move on. If no, and it’s going somewhere hostile, give it a declarative shadow root and expose a small set of parts and custom properties on purpose.

And if it’s an internal app screen with forms, tables and state, use your framework. Shipping it twice to prove a point about the platform is the most expensive mistake in this whole area, and we’ve been the ones billing to undo it.

cross-root aria shadow dom accessibility custom elements without shadow dom declarative shadow dom server rendering form associated custom elements ElementInternals light dom html web components pattern styling shadow dom with ::part and custom properties using custom elements in React 19 web components vs framework components