Cette page est affichée en anglais. Une traduction française est en cours.
SkillsApr 11, 2026·2 min de lecture

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.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
step-1.md
Commande d'installation directe
npx -y tokrepo@latest install 25e2a55c-35b8-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

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.

Questions fréquentes

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.

Sources citées (3)

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires