Overview

1 The framework without a framework

This chapter frames Web Components as a “framework without a framework,” responding to the rapid churn of frontend tools and the team-level challenges that follow. It argues that developers can regain stability and longevity by leaning on browser standards—HTML, CSS, and JavaScript—while still getting the structure, reuse, and clear APIs that frameworks promise. The central idea is to favor durable, interoperable building blocks over framework-specific systems, so teams can share UI, scale across projects, and evolve without wholesale rewrites.

After motivating the need, the chapter explains what Web Components are and how they work: Custom Elements let you define new DOM elements with their own APIs; the Shadow DOM provides encapsulation so styles and DOM structure don’t leak; and standard attributes, properties, methods, and events form the public surface. It revisits the rocky history—HTML Imports’ failure, uneven Shadow DOM support, and early reliance on libraries like Polymer and X-Tags—and shows how modern ES2015+ features (modules, import, template literals, arrow functions) have made Web Components practical and pleasant. With broad browser adoption and lightweight libraries such as lit-html and LitElement, the emphasis shifts to Custom Elements as the core, with Shadow DOM and the template tag as optional tools.

The chapter then moves beyond single components to composing full applications. It treats components like any DOM element: design clear properties and methods, reflect attributes to properties when appropriate, and communicate via native and custom events. For cross-tree messaging, an event bus can complement or replace DOM bubbling, and microframeworks can add targeted capabilities without imposing a heavy architecture. Looking ahead, components compiled from React, Angular, Vue, or tools like Stencil and Svelte can interoperate as standard elements, and even WebAssembly-backed components may fit the model. The takeaway: choose what fits your team and project, but consider Web Components a viable, standards-based foundation for today and the future.

Expanded date picker UI
Enabling shadow root settings in the Chrome dev tools allows us to see the input tag’s hidden Shadow DOM.
The Shadow DOM protects your component from unintended consequences when CSS or JS might affect styles and nodes inside that aren’t meant to be altered. Instead, your component would have a custom-defined API to interact with using methods and properties.
With HTML Imports, a file containing your component definition and your component’s markup could be imported right into your document.
Web Components could bridge the gap in the future between popular frameworks. Not only can no-framework Web Components be used in these frameworks, but there are already experimental projects to compile a component in React, Angular, or Vue to independently run components that can be used anywhere.
DOM elements have various properties, methods, events, and attributes that are used to tell the element how to act and communicate with the outside world.
Example web application comprised of Web Components, which are themselves made up of more Web Components. The hierarchy can extend to something small, like a custom button, or be as large as the entire application wrapped as a Web Component.
Events naturally bubble from the inside out of nested elements.
If normal event bubbling is not desirable, with a bit of code, you can create an event bus system to route events where you want.

   Summary

In this chapter, you learned

  • How Web Components have evolved in the past few years from a Google-owned working draft to a real web standard adopted by all the modern browsers
  • The Shadow DOM as an optional yet important feature, while being on the verge of widespread browser adoption
  • Web Components’ place in modern frameworks, as well as an agnostic part of any ecosystem
  • The potential future of Web Components with an ever-expanding community of JS modules in the spirit of Polymer Project libraries like lit-html and lit-element, as well as non-Polymer Project ones like hyperHTML
  • The individual Web Component versus an entire Web Component application

FAQ

What are Web Components?They are standardized, reusable UI building blocks made with web platform features. At their core are Custom Elements (your own HTML tags), optionally using Shadow DOM for encapsulation, plus modern JavaScript features for structure and reuse.
How does the Shadow DOM work, and why use it?Shadow DOM creates an isolated subtree whose markup and styles are shielded from the page. This prevents external CSS and DOM queries from accidentally breaking your component, and encourages interaction through a clear public API (properties, methods, and events).
What are Custom Elements and how do they expose an API?Custom Elements let you define new tags with lifecycle callbacks. They expose functionality through properties and methods, accept configuration via attributes, and communicate changes with events. A common best practice is “reflection,” keeping attributes and properties in sync.
What happened to HTML Imports, and what replaces them?HTML Imports never gained cross-browser adoption and were dropped from the vision. ES modules (import/export) and template literals now fill that role, letting each component load its own dependencies and render markup without a separate HTML import mechanism.
Do I need a framework to build with Web Components?No. You can build with standards alone—the “framework without a framework” approach—and add small, targeted libraries only when needed. This reduces lock-in, emphasizes core web skills, and keeps your stack lightweight.
Which ES6/ES2015 features are especially helpful?Modules and the import keyword provide robust dependency management per component. Template literals simplify rendering markup and composing templates; arrow functions help with lexical this in event handlers and timers; classes enable inheritance for shared behaviors.
Is the Shadow DOM required?It’s optional. It provides strong encapsulation, but you can ship components without it, add it later, or use fallbacks; early full polyfills were heavy, which is why some projects used “Shady DOM” as a lighter workaround.
How do components work together in an application?Compose components hierarchically and use events for communication. Leverage native bubbling and CustomEvent, or introduce a simple event bus when you need to pass messages across distant parts of the DOM without relying on bubbling paths.
How do Polymer and X-Tags relate to modern practices like lit-html and LitElement?Polymer and X-Tags were early libraries that helped developers through a period of unstable specs and uneven browser support. The ecosystem has since moved toward smaller, focused tools—like lit-html and LitElement—that align well with a no-framework, standards-first workflow.
What does the future look like for framework interoperability?Components built in React, Angular, or Vue can be compiled into standalone Web Components, enabling mix-and-match use across stacks. This trend, along with module-based libraries and even WebAssembly-powered parts, points to fewer walls between frameworks and languages.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Web Components in Action ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Web Components in Action ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Web Components in Action ebook for free