talira

Simple. Fast. Web Components.

open sourceBSD-3-Clauseself-hostablefree

Lit is a small library for building fast, lightweight web components. Its LitElement base class adds reactive properties, Shadow DOM-scoped styles and declarative templates written as tagged template literals, and it updates only the dynamic parts of the UI rather than diffing a virtual DOM, in about 5 KB minified and compressed. Every Lit component is a native custom element, so it works in plain HTML or inside any framework, which makes Lit a common choice for shareable components and design systems. The monorepo also has @lit/localize, @lit/context, @lit/task, a React wrapper and labs packages for server-side rendering, routing and signals. Lit is part of the OpenJS Foundation and is BSD-3-Clause licensed.

Problems it solves

  • build UI components once and use them in React, Vue, Angular or plain HTML
  • our design system has to work across teams using different frontend frameworks
  • writing native custom elements by hand takes too much boilerplate
  • keep a component's CSS from leaking into the rest of the page and vice versa
  • a tiny component library that doesn't add much to the bundle
  • re-render a component when one of its attributes or properties changes
  • render web components on the server and hydrate them in the browser
  • embed widgets in pages built by a CMS or static site generator

Features

  • LitElement base class for native custom elements
  • reactive properties and attributes that trigger efficient re-renders
  • styles scoped with Shadow DOM
  • declarative templates with tagged template literals (lit-html)
  • about 5 KB minified and compressed
  • TypeScript decorators or plain JavaScript
  • @lit/localize, @lit/context, @lit/task and @lit/react packages
  • labs packages for server-side rendering (@lit-labs/ssr), routing, motion and signals
  • online playground

Alternatives

The same job

These do what Lit does.

  1. Svelte Web development for the rest of us
  2. React The library for web and native user interfaces
  3. Preact Fast 3kB alternative to React with the same modern API
  4. Vue.js The Progressive JavaScript Framework

Compare Lit with the top 3