Search⌘ K

Overview of Stencil

Explore Stencil as a compiler tool to create reusable, standards-based web components using Virtual DOM, reactive data binding, JSX, and TypeScript. Understand its benefits for performance, encapsulation, and cross-framework compatibility.

What is Stencil?

Stencil is a compiler tool developed by the team at Ionic specifically for the generation of standards-based Web Components and has been used since Ionic 4 for the creation of all their UI components.

For those who are new to Web Components, these are self-contained bundles of HTML, JavaScript/TypeScript, and CSS that are encapsulated away from the main code of our applications to create reusable widgets and components.

Web Components can be developed this way through the use of the following APIs and standards:

  • Custom Elements: A set of JavaScript APIs that developers can utilize to generate custom HTML elements and define their respective behaviors
  • Shadow DOM: A set of JavaScript APIs that allow for the creation of a “shadow” DOM tree (one that is entirely separate from the main DOM), which allows for features to be self-encapsulated. In other words, this means they are not able to affect or be affected by other parts of the main DOM tree
  • HTML Templates: Reusable chunks of HTML can be defined through the <template> and <slot> elements, allowing them to be used in conjunction with the Custom Elements API
  • Modules: Defines how JavaScript modules can be imported or reused in a standards-based, performant manner

Benefits of using Web Components

The benefits of using Web ...