Search code examples
javascriptweb-componentlit-elementlit-htmllit

What is the difference between lit-element & lit-html?


I have been learning Polymer and this came in - The future of web (lit-element & lit-html)

I understood that lit-html is for HTML templating with a couple of efficient techniques. At the same time lit-element is a lightweight web component base class which has the lit-html inside it.

Question: If lit-element comes with lit-html, I would solely use the lit-element for all my purposes. What exactly does lit-html doing explicitly with its own separate context.

One should choose lit-element or lit-html while developing a standalone web application?

Any help on guiding through this would be of much help!


Solution

  • First, lets clarify the following points:

    • Web Components technologies are supported in modern browsers by default. You can build a Web Component application using the browser's API.

    • HTML templates has been around since 2013 at least.

    lit-element library is a "lightweight" version of Web Components. You'd use it if you want to build an application in Web Component and if you do so, you'd be using its built-in lit-html via html to create HTML templates

    On the other hand, Just like you stated, lit-html is a library which has efficient mechanism to create and update HTML templates. You can use it for whenever you'd need an HTML template irrespective of the framework/library you are using for your website, if any.

    For an example, you could build a website with jQuery or vanilla Web Components and use lit-html to create the HTML templates.