Lit is a tiny library for building web components — reusable custom HTML elements that work in any framework, or in no framework at all. If you have ever wanted to build a <my-card> or <date-picker> element that you can drop into any page, Lit is one of the simplest ways to do it.
A web component is a custom element with its own encapsulated styles and behavior, powered by the browser's native Custom Elements and Shadow DOM APIs. Lit adds a thin layer on top: declarative templates, reactive properties, and efficient re-rendering. You write a class, Lit handles the rest.
Here is a complete Lit component:
import { LitElement, html, css } from 'lit';
import { customElement, property } from 'lit/decorators.js';
@customElement('hello-card')
export class HelloCard extends LitElement {
static styles = css`
.card { padding: 16px; border: 1px solid #ddd; border-radius: 8px; }
`;
@property() name = 'World';
render() {
return html`<div class="card">Hello, ${this.name}!</div>`;
}
}
Use it anywhere with <hello-card name="Arhan"></hello-card>. The @property() decorator makes name reactive — change the attribute and the component re-renders automatically. The html template tag handles escaping and efficient updates, so you only re-render what changed.
To start, install Lit with npm install lit and import it in any project — Vite, plain HTML with an import map, or an existing app. There is no build step required for the basics, though a bundler helps for production.
Lit is a great fit if you build design systems, widgets embedded in other people's pages, or components that must survive framework changes. Because the output is a standard web component, it works in React, Vue, Angular, or plain HTML without wrappers.
The limits are honest ones. Lit gives you components, not an app framework — there is no built-in router or state store, so you bring your own for large apps. The decorator syntax needs a build step or a modern browser setup, and the ecosystem is smaller than the big frameworks.
Start small: convert one repeated piece of UI in your current project — a button, a card, a modal — into a Lit component. If you enjoy how portable it feels, you have found your use case.
Top comments (1)
Or without Lit in native Web Components: