Which is Better Web Component Libraries?
lit-html vs lit-element
1 Year
lit-htmllit-elementSimilar Packages:
What's Web Component Libraries?

LitElement and LitHtml are part of the Lit library ecosystem, designed to simplify the creation of web components. LitElement provides a base class for creating custom elements with reactive properties, while LitHtml offers a powerful templating engine for rendering HTML efficiently. Together, they enable developers to build fast, lightweight, and reusable components that adhere to the web standards of custom elements and shadow DOM. The primary advantage of using these libraries is their focus on performance and ease of use, allowing developers to create dynamic user interfaces with minimal boilerplate code.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
lit-html2,400,00218,6781.71 MB51713 days agoBSD-3-Clause
lit-element1,996,53318,678122 kB51713 days agoBSD-3-Clause
Feature Comparison: lit-html vs lit-element

Component Creation

  • lit-html: LitHtml does not create components itself but provides a powerful templating syntax that can be used within LitElement or any other framework. It allows for efficient rendering of HTML templates, enabling developers to create dynamic and interactive user interfaces.
  • lit-element: LitElement simplifies the creation of web components by providing a base class that handles property declaration, observation, and lifecycle methods. This allows developers to focus on building their components without worrying about the underlying complexities of the web component standards.

Reactivity

  • lit-html: LitHtml focuses on rendering and does not manage state directly. However, it works seamlessly with LitElement's reactive properties, allowing developers to leverage reactivity in their templates without additional overhead.
  • lit-element: LitElement introduces a reactive property system that automatically updates the component when properties change. This ensures that the UI is always in sync with the underlying data model, making it easier to manage state within components.

Performance

  • lit-html: LitHtml is designed for high performance, using a fine-grained update mechanism that only re-renders parts of the DOM that have changed. This reduces unnecessary DOM manipulations and improves rendering speed, especially in complex applications.
  • lit-element: LitElement is optimized for performance, utilizing the shadow DOM for encapsulation and efficient updates. It minimizes reflows and repaints in the browser, leading to faster rendering times and a smoother user experience.

Learning Curve

  • lit-html: LitHtml is relatively easy to learn, particularly for those with a background in JavaScript and HTML. Its templating syntax is intuitive, allowing developers to quickly grasp how to create dynamic content without extensive boilerplate.
  • lit-element: LitElement has a moderate learning curve, especially for developers familiar with web components. Its API is straightforward, making it accessible for those new to web component development while still offering advanced features for experienced developers.

Integration

  • lit-html: LitHtml can be used independently or in conjunction with LitElement. It can also be integrated into other frameworks, making it a versatile choice for rendering HTML in various contexts, whether in standalone applications or within larger frameworks.
  • lit-element: LitElement integrates well with other libraries and frameworks, allowing developers to use it alongside existing codebases. It can be easily incorporated into projects that utilize frameworks like React, Vue, or Angular, providing flexibility in component design.
How to Choose: lit-html vs lit-element
  • lit-html: Choose LitHtml if your primary need is an efficient templating engine for rendering HTML. It is suitable for applications where you want to create dynamic content without the overhead of a full framework, and you prefer a lightweight solution for rendering views.
  • lit-element: Choose LitElement if you need a robust framework for building reusable web components with reactive properties and lifecycle management. It is ideal for projects that require encapsulated styles and behavior, leveraging the power of custom elements.
README for lit-html

lit-html 2.0

Efficient, Expressive, Extensible HTML templates in JavaScript

Build Status Published on npm Join our Discord Mentioned in Awesome Lit

lit-html is the template system that powers the Lit library for building fast web components. When using lit-html to develop web components, most users should import lit-html via the lit package rather than installing and importing from lit-html directly.

About this release

This is a pre-release of Lit 3.0, the next major version of Lit.

Lit 3.0 has very few breaking changes from Lit 2.0:

  • Drops support for IE11
  • Published as ES2021
  • Removes a couple of deprecated Lit 1.x APIs

Lit 3.0 should require no changes to upgrade from Lit 2.0 for the vast majority of users. Once the full release is published, most apps and libraries will be able to extend their npm version ranges to include both 2.x and 3.x, like "^2.7.0 || ^3.0.0".

Lit 2.x and 3.0 are interoperable: templates, base classes, directives, decorators, etc., from one version of Lit will work with those from another.

Please file any issues you find on our issue tracker.

Documentation

Full documentation is available at lit.dev.

Overview

lit-html lets you write HTML templates in JavaScript with template literals.

lit-html templates are plain JavaScript and combine the familiarity of writing HTML with the power of JavaScript. lit-html takes care of efficiently rendering templates to DOM, including efficiently updating the DOM with new values.

import {html, render} from 'lit-html';

// This is a lit-html template function. It returns a lit-html template.
const helloTemplate = (name) => html`<div>Hello ${name}!</div>`;

// This renders <div>Hello Steve!</div> to the document body
render(helloTemplate('Steve'), document.body);

// This updates to <div>Hello Kevin!</div>, but only updates the ${name} part
render(helloTemplate('Kevin'), document.body);

lit-html provides two main exports:

  • html: A JavaScript template tag used to produce a TemplateResult, which is a container for a template, and the values that should populate the template.
  • render(): A function that renders a TemplateResult to a DOM container, such as an element or shadow root.

Installation

$ npm install lit-html

Or use from lit:

$ npm install lit

Contributing

Please see CONTRIBUTING.md.