Web components vs framework components: where do they fit?
Web components are a set of browser-native standards for building reusable custom elements. They let you create a tag like <user-card> that works in any page, with or without a framework.
The building blocks:
- Custom elements: define new HTML tags with JavaScript classes and lifecycle callbacks.
- Shadow DOM: encapsulated DOM and styles, so the component's CSS doesn't leak out and page CSS doesn't leak in.
- HTML templates and slots: reusable markup and placeholders for content passed in.
Where web components shine:
- Design systems shared across teams using different frameworks
- Embeddable widgets for third-party sites
- Long-lived components that should outlast framework changes
- Progressive enhancement of mostly server-rendered pages
Where framework components still win:
- Rich state management, routing and data-fetching patterns
- Ergonomics: templating, reactivity and tooling are more built-in
- Server-side rendering support, which is improving for web components (declarative shadow DOM) but still less seamless
- Large ecosystems of ready-made components
Friction points:
- Shadow DOM encapsulation makes global styling and theming harder; CSS custom properties and
::parthelp. - Form participation and accessibility need extra care.
- Passing complex data via attributes is limited; properties are used instead.
Libraries exist that make authoring web components feel more like a framework.
Have you shipped web components in production? Would you build a design system on them today?
Comments · 3
As a beginner, should I learn a framework or web components first? I keep hearing both are worth knowing.
Web components are appealing for design systems because they work in any framework. One button, every product.
Don't overthink it. Pick whatever your team already knows. Switching for purity costs more than it saves.