Define a Lit component by creating a class extending LitElement and registering your class with the browser:

The TypeScript @customElement decorator is a shorthand for the JavaScript equivalent of calling customElements.define, which registers the custom element class with the browser and associates it with the custom element name word-viewer.

customElements.define registers the custom element class with the browser and associates it with the custom element name word-viewer.

A valid custom element name must contain a hyphen.

This ensures forward compatibility with future tags added to HTML or SVG which won't add hyphen containing elements.

Rendering

Permalink to "Rendering"

A Lit component's render() method returns a template. Lit templates use the html tagged template literal to run without a build step in JavaScript.

Add a template to define what word-viewer should render:

If using TypeScript, you can register your custom element on the HTMLElementTagNameMap.

Doing this allows TypeScript to infer the type of document.createElement('word-viewer') as your WordViewer class.

Result

Permalink to "Result"

You should see A super expressive and efficient template! rendered in the preview.