Stencil
Web Components compiler created by Ionic, generating optimized framework-agnostic native standard components for maximum performance.
Updated on February 7, 2026
Stencil is a modern compiler that transforms TypeScript/JSX code into highly optimized, native standard Web Components. Developed by the Ionic team, it combines best practices from modern frameworks (Virtual DOM, reactivity, TypeScript) while producing vanilla JavaScript code that leverages web standards. This approach enables creating reusable components in any context, without runtime dependencies.
Fundamentals of Stencil
- Compiler, not framework: generates standard code without additional runtime
- Native Web Components: Custom Elements, Shadow DOM, and standard slots
- Modern Developer Experience: TypeScript, JSX, decorators, hot reload
- Optimized output: automatic lazy loading, code splitting, conditional polyfills
Benefits of Stencil
- Framework-agnostic: components usable with React, Vue, Angular or vanilla JS
- Native performance: no runtime Virtual DOM, only during build
- Minimal bundle size: each component loads only what it needs
- Web standards: relies on native APIs for maximum longevity
- Robust ecosystem: used in production by Ionic, Microsoft, Apple
- Built-in TypeScript: strong typing and autocompletion without configuration
Practical Component Example
import { Component, Prop, State, h } from '@stencil/core';
@Component({
tag: 'my-counter',
styleUrl: 'my-counter.css',
shadow: true
})
export class MyCounter {
@Prop() initialValue: number = 0;
@State() count: number;
componentWillLoad() {
this.count = this.initialValue;
}
increment = () => {
this.count += 1;
}
render() {
return (
<div class="counter">
<p>Count: {this.count}</p>
<button onClick={this.increment}>
Increment
</button>
</div>
);
}
}This component can then be used as a simple HTML tag in any application: <my-counter initial-value="10"></my-counter>
Implementation in a Project
- Initialize project: npm init stencil component my-library
- Develop components using decorators @Component, @Prop, @State, @Event
- Compile with npm run build: generates optimized bundles
- Publish to npm: components are distributed as standard package
- Consume in any framework via import or CDN
- Generate framework-specific wrappers for better integration
Pro Tip
Use Stencil's automatic React/Angular/Vue wrapper generator to provide native experience in each framework while maintaining a single source of truth. Configure lazy loading to load components only when they appear in the DOM, drastically reducing time-to-interactive.
Related Tools and Ecosystem
- Ionic Framework: mobile component library built with Stencil
- Stencil Router: routing for Web Components applications
- Stencil Testing: integrated testing with Jest and Puppeteer
- Storybook: component documentation and showcase
- Design Systems: Shoelace, Microsoft FAST, use Stencil
Business Impact and Sustainability
Stencil addresses long-term maintainability challenges by creating components based on web standards rather than proprietary abstractions. For enterprise design systems, this means a component library usable regardless of teams' technological choices, reducing technical debt and facilitating migrations. Native performance and minimal bundle size translate into better Core Web Vitals metrics, directly impacting SEO and conversion rates. The initial investment in Stencil is amortized through maximum code reusability and independence from JavaScript framework lifecycles.

