ConfigsApr 11, 2026·2 min read

Lit — Simple Library for Fast Lightweight Web Components

Lit is a simple library for building fast, lightweight web components. Built by Google on top of the standard Web Components APIs, it provides reactive properties, scoped styles, and a declarative templating system in about 5KB.

TL;DR
Lit builds standards-based web components with reactive properties, scoped styles, and declarative templates in 5KB.
§01

What it is

Lit is a library built by Google for creating web components using standard Web Components APIs. It adds reactive properties, scoped CSS styles, and a declarative HTML templating system on top of the native Custom Elements and Shadow DOM specifications. The entire library is about 5KB gzipped.

Lit targets frontend developers who want framework-agnostic UI components. Components built with Lit work in any framework (React, Vue, Angular) or with no framework at all, because they compile down to native browser APIs.

§02

How it saves time or tokens

This workflow provides the npm install and a working component template. Instead of learning the raw Custom Elements API and Shadow DOM boilerplate, you get a class-based component model with automatic re-rendering when properties change. The included counter example is a complete, runnable component.

§03

How to use

  1. Install Lit:
npm i lit
  1. Create a web component:
import { LitElement, html, css } from 'lit';
import { customElement, property } from 'lit/decorators.js';

@customElement('my-counter')
export class MyCounter extends LitElement {
  static styles = css`
    button { padding: 8px 16px; font-size: 16px; }
    span { margin: 0 12px; font-weight: bold; }
  `;

  @property({ type: Number }) count = 0;

  render() {
    return html`
      <button @click=${() => this.count--}>-</button>
      <span>${this.count}</span>
      <button @click=${() => this.count++}>+</button>
    `;
  }
}
  1. Use the component in any HTML page:
<script type="module" src="./my-counter.js"></script>
<my-counter count="5"></my-counter>
§04

Example

import { LitElement, html, css } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';

@customElement('user-card')
export class UserCard extends LitElement {
  static styles = css`
    :host { display: block; border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; }
    .name { font-size: 1.2em; font-weight: 600; }
    .email { color: #6b7280; }
  `;

  @property() name = '';
  @property() email = '';
  @state() private expanded = false;

  render() {
    return html`
      <div class="name">${this.name}</div>
      <div class="email">${this.email}</div>
      <button @click=${() => this.expanded = !this.expanded}>
        ${this.expanded ? 'Less' : 'More'}
      </button>
      ${this.expanded ? html`<slot></slot>` : ''}
    `;
  }
}
§05

Related on TokRepo

§06

Common pitfalls

  • Lit uses Shadow DOM by default, which scopes styles. Global CSS does not penetrate shadow boundaries. Use CSS custom properties (variables) for theming across components.
  • TypeScript decorators (@customElement, @property) require experimentalDecorators in tsconfig.json. Without it, compilation fails.
  • Lit components must be registered with unique tag names. Using a name that conflicts with existing HTML elements or other custom elements causes errors.

Frequently Asked Questions

How does Lit compare to React?+

Lit produces native web components that work without a framework runtime. React requires the React library to render components. Lit components are smaller and framework-agnostic, while React has a larger ecosystem and more community resources.

Can I use Lit components in React or Vue?+

Yes. Lit components are standard HTML custom elements. In React, use them like any HTML tag. In Vue, register them as custom elements. No wrappers or adapters needed because they use native browser APIs.

How large is the Lit library?+

About 5KB gzipped. This includes the template system, reactive properties, and scoped styles. It is significantly smaller than React (40KB+) or Angular (100KB+).

Does Lit support server-side rendering?+

Yes. Lit provides an SSR package (@lit-labs/ssr) that renders components to HTML strings on the server. The client-side library then hydrates the rendered HTML for interactivity.

Is Lit production-ready?+

Yes. Lit is maintained by Google and used in production by Google, Adobe, ING Bank, and other organizations. It is the successor to the Polymer library and has been stable since version 2.0.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets