Skip to content
A Web Component compiler for building fast, reusable UI components and Progressive Web Apps πŸ’Ž Built by the Ionic Framework team
TypeScript HTML Other
Branch: master
Clone or download
adamdbradley and CSchulz feat(bundling): add webpack chunk name
Closes #1345 #1346

Co-Authored-By: CSchulz <>
Latest commit 3ca7d82 Jan 19, 2020
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github chore(build): npm ci karma tests Dec 19, 2019
.vscode fix(hydrate): fix scoped/ie11/edge clientside slot hydrate Dec 21, 2019
bin refactor(config): expose createSystem and pass to loadConfig Dec 10, 2019
screenshot refactor(compiler): improve incremental builds and css imports Nov 27, 2019
scripts chore(build): manually set version on release Jan 15, 2020
src feat(bundling): add webpack chunk name Jan 19, 2020
test chore: dash case "custom-elements-bundle" directory Jan 14, 2020
types refactor(compiler): improve incremental builds and css imports Nov 27, 2019
.editorconfig chore(): add editorconfig settings. May 11, 2017
.gitignore refactor(compiler): improve incremental builds and css imports Nov 27, 2019 chore(): update plugins to 1.0.0 Jun 9, 2019 πŸ’ͺ 1.9.0-12 Jan 15, 2020 docs(CoC): add code of conduct Oct 19, 2017 chore(license): update license (#1955) Oct 15, 2019 fix(test): lock in working version of fast-deep-equal Jan 14, 2020 refactor(watch): replace decorator PropWill/DidChange w/ Watch Jan 9, 2018
package-lock.json 🚌 1.9.0-12 Jan 14, 2020
package.json 🚌 1.9.0-12 Jan 14, 2020 docs(readme): code example missing import (#2092) Dec 19, 2019
rollup.config.js refactor(compiler): improve incremental builds and css imports Nov 27, 2019
tsconfig.json fix(compiler): fix circular dependency with @app-globals Dec 20, 2019

npm Build & Test license

Stencil: A Compiler for Web Components and PWAs

npm init stencil

Stencil is a simple compiler for generating Web Components and progressive web apps (PWA). Stencil was built by the Ionic Framework team for its next generation of performant mobile and desktop Web Components.

Stencil combines the best concepts of the most popular frontend frameworks into a compile-time rather than run-time tool. It takes TypeScript, JSX, a tiny virtual DOM layer, efficient one-way data binding, an asynchronous rendering pipeline (similar to React Fiber), and lazy-loading out of the box, and generates 100% standards-based Web Components that run on both modern browsers and legacy browsers back to Internet Explorer 11.

Stencil components are just Web Components, so they work in any major framework or with no framework at all. In many cases, Stencil can be used as a drop in replacement for traditional frontend frameworks given the capabilities now available in the browser, though using it as such is certainly not required.

Stencil also enables a number of key capabilities on top of Web Components, in particular Server Side Rendering (SSR) without the need to run a headless browser, pre-rendering, and objects-as-properties (instead of just strings).

Note: Stencil and Ionic are completely independent projects. Stencil does not prescribe any specific UI framework, but Ionic is the largest user of Stencil (today!)

Why Stencil?

Stencil is a new approach to a popular idea: building fast and feature-rich apps in the browser. Stencil was created to take advantage of major new capabilities available natively in the browser, such as Custom Elements v1, enabling developers to ship far less code and build faster apps that are compatible with any and all frameworks.

Stencil is also a solution to organizations and library authors struggling to build reusable components across a diverse spectrum of frontend frameworks, each with their own component system. Stencil components work in Angular, React, Ember, and Vue as well as they work with jQuery or with no framework at all, because they are just plain HTML elements.

Compared to using Custom Elements directly, inside of every Stencil component is an efficient Virtual DOM rendering system, JSX rendering capabilities, asynchronous rendering pipeline (like React Fiber), and more. This makes Stencil components more performant while maintaining full compatibility with plain Custom Elements. Think of Stencil as creating pre-baked Custom Elements as if you wrote in those features yourself.

Getting Started

To create a new project using an interactive cli, run:

npm init stencil

To start developing your new Stencil project, run:

npm start

Creating components

Stencil components are plain ES6/TypeScript classes with some decorator metadata.

Create new components by creating files with a .tsx extension, such as my-component.tsx, and place them in src/components.

import { Component, Prop, h } from '@stencil/core';

  tag: 'my-component',
  styleUrl: 'my-component.css'
export class MyComponent {

  @Prop() first: string;

  @Prop() last: string;

  render() {
    return (
        Hello, my name is {this.first} {this.last}

Note: the .tsx extension is required, as this is the standard for TypeScript classes that use JSX.

To use this component, just use it like any other HTML element:

<my-component first="Stencil" last="JS"></my-component>

Naming Components

When creating new component tags, we recommend not using stencil in the component name (ex: <stencil-datepicker>). This is because the generated component has little to nothing to do with Stencil; it's just a web component!

Instead, use a prefix that fits your company or any name for a group of related components. For example, all of the Ionic generated web components use the prefix ion.

Hosting the app

Stencil components run directly in the browser through script includes just like normal Custom Elements (because they are just that!), and run by using the tag just like any other HTML component:

Here's an example index.html file that runs a Stencil app:

<!doctype html>
  <title>My App</title>
  <script src="build/app.js"></script>
  <my-component first="Stencil" last="JS"></my-component>


The API for stencil closely mirrors the API for Custom Elements v1.


Decorator Description
@Component() Indicate a class is a Stencil component.
@Prop() Creates a property that will exist on the element and be data-bound to this component.
@State() Creates a local state variable that will not be placed on the element.
@Method() Expose specific methods to be publicly accessible.

Why "Stencil?"

A Stencil is a tool artists use for drawing perfect shapes easily. We want Stencil to be a similar tool for web developers: a tool that helps web developers build powerful Web Components and apps that use them, but without creating non-standard runtime requirements.

Stencil is a tool developers use to create Web Components with some powerful features baked in, but it gets out of the way at runtime.

Using Web Components in Ionic - Polymer Summit 2017

Browser Support

Web Components, specifically Custom Elements, are natively supported in Chrome and Safari and are coming to both Edge and Firefox. A dynamic polyfill loader is already included in order to only load the polyfills for the browsers that are missing specific features.

  • Chrome (and all Chromium based browsers)
  • Safari
  • Edge
  • Firefox
  • IE 11


Stencil includes a subset of the core-js polyfills for old browsers like IE11, fetch and conditionally downloads the Custom Elements v1 only when it's needed for modern browsers (EDGE and old versions of Firefox.)

Internet Explorer 11

Browsers that do not support native ESM (at the moment, only IE11 and older) will download a subset of core-js.

This subset is generated using the core-js-builder tool with the following configuration:

  targets: 'ie 11',
  modules: [
  blacklist: [

In addition, the following set of polyfills are also included:

All browsers

Some modern browsers like Edge do not include native support for Web Components. In that case, we conditionally load the Custom Elements v1 polyfill.



You can’t perform that action at this time.