3 Vanilla web components
This chapter covers
- Patterns for implementing vanilla web components
- Shadow DOM
- Styling web components
- Contributing to form submissions
- Sharing state across web components
"Vanilla" web components are web components built directly on web component standards, without relying on helper libraries such as Lit, Stencil, FAST, or wrec. These libraries are layered on top of the same underlying browser APIs used by vanilla web components. So developing a solid understanding of the vanilla approach provides a strong foundation for working effectively with any web component library.
Even if you choose to use libraries in your projects, vanilla web components remain relevant in real-world development. You may encounter existing codebases built with vanilla web components and need to debug or extend them. You may also decide that a lightweight, dependency-free solution is the best fit for particular use cases. In these situations, familiarity with the core concepts including custom elements, templates, Shadow DOM, and lifecycle callbacks is critical.
Understanding how vanilla web components are implemented clarifies why libraries were created. But vanilla web components can suffer from boilerplate code, rendering concerns, and complex state management. Seeing these issues firsthand helps you to appreciate how libraries streamline development and improve maintainability.