Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
A basic LitElement counter component with dark/light theme toggle.
import { LitElement, html, css } from 'lit';
import { customElement, state } from 'lit/decorators.js';
@customElement('lit-counter')
export class LitCounter extends LitElement {
@state() count = 0;
@state() isDark = false;
static styles = css`
.dark-theme { background-color: #222; color: #eee; }
.light-theme { background-color: #fff; color: #000; }
`;
render() {
return html`
<div class=${this.isDark ? 'dark-theme' : 'light-theme'}>
<h2>Counter: ${this.count}</h2>
<div>
<button @click=${() => this.count++}>+</button>
<button @click=${() => this.count--}>-</button>
<button @click=${() => this.count = 0}>Reset</button>
</div>
<button @click=${() => this.isDark = !this.isDark}>Switch to ${this.isDark ? 'Light' : 'Dark'} Theme</button>
</div>
`;
}
}Lit is a lightweight, fast, web-component-focused library for building reactive and declarative UI using standard web platform features. It emphasizes interoperability, small bundle sizes, and declarative templating with lit-html.
Origin & Creator
Created by Google’s Polymer team, originally derived from lit-html and Polymer projects. First public release in 2019 as a modern, lightweight web component library.
Industrial Note
Lit excels in projects where web standards, framework interoperability, or lightweight, fast UI components are required, such as design systems, component libraries, and embeddable widgets.