lit-html is a concise and efficient JavaScript library for creating declarative HTML templates using standard JavaScript template literals. It enables developers to render and dynamically update DOM with high performance, as it only modifies the specific parts of the DOM that have changed, avoiding the overhead of a virtual DOM. Currently at version 3.3.2, lit-html is actively maintained as a core part of the Lit project, which focuses on building fast and lightweight web components. It differentiates itself through its tight integration with native browser APIs, small bundle size, and a highly optimized rendering engine. While it can be used standalone, most users developing web components with the Lit library are encouraged to import its functionalities through the main `lit` package for a more integrated development experience. Its release cadence typically aligns with the broader Lit ecosystem updates, often seeing patch releases and minor versions together.
npm install lit-htmlVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining a dynamic lit-html template with event handling and efficiently updating the DOM.
Update imports to use ES module syntax (e.g., `import { html, render } from 'lit-html';`). Ensure your build setup correctly handles ESM.Review the Lit 3.0 upgrade guide for specific API changes. Ensure your project uses TypeScript 5.0+ and Node.js 18+ for development and build environments.
Always update the data passed to your lit-html templates and let `render()` handle the DOM updates. Avoid direct DOM manipulation for elements within a `lit-html` rendered scope.
Ensure distinct DOM containers are used for different rendering libraries. If integrating with web components, use the component's shadow DOM to encapsulate `lit-html` rendering.
Add `import { html } from 'lit-html';` to the top of your module.Ensure `import { render } from 'lit-html';` is used. If using CommonJS, verify your environment supports it or migrate to ESM.Add `type="module"` to your script tag in HTML (e.g., `<script type="module" src="./my-app.js"></script>`) or ensure your build process correctly transpiles and bundles for your target environment.