Lit — guide & examples
Modern Web Components playground powered by LitElement with reactive properties, scoped styles, and instant updates.
About Lit
Modern Web Components playground powered by LitElement with reactive properties, scoped styles, and instant updates.
Runtime: v3.3.3
Features
- Lit 3.3
- Reactive Properties
- Scoped CSS
- Shadow DOM
- Local File Imports
- Custom Elements
Browser playground limits
- • Code runs in a sandboxed browser preview, without Node.js, a backend, or private environment variables.
- • The Console prompt can inspect browser globals and the rendered DOM, but not variables scoped inside ES modules or component state.
- • Download the project when you need build plugins, server APIs, native modules, or a production dependency workflow.
How to use the Lit playground
- Edit a source file from the project explorer — the live preview recompiles automatically.
- Add, rename, duplicate or delete project files as needed. Update affected imports after renaming or moving a file.
- Use the console for logs and errors, and Format to tidy the active file.
- Share the complete project or download a Vite project ZIP with its source files and package.json.
Editing
Select next occurrenceCtrl / ⌘+D
Delete lineCtrl / ⌘+Shift+K
Move line up / downAlt+↑ / ↓
Copy line up / downAlt+Shift+↑ / ↓
Navigation
Go to symbolCtrl / ⌘+Shift+O
Selection
Select all occurrencesCtrl / ⌘+Shift+L
Terminal
Interrupt / kill processCtrl+C
Send EOF (close stdin)Ctrl+D
Console shortcuts
Press Enter to evaluate, ↑ and ↓ to browse command history, and Ctrl/⌘ + L to clear the console.
import './components/counter-card.js'
import './styles.css'
console.log('Lit custom element registered')
src/components/counter-card.js import { LitElement, css, html } from 'lit'
class CounterCard extends LitElement {
static properties = {
count: { type: Number },
}
static styles = css`
.card {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1.5rem;
padding: 1.25rem;
border: 1px solid #d8d4fe;
border-radius: 1.25rem;
background: white;
}
strong {
font-size: 2rem;
}
button {
border: 0;
border-radius: 999px;
padding: 0.8rem 1.15rem;
background: #6366f1;
color: white;
font: inherit;
cursor: pointer;
}
`
constructor() {
super()
this.count = 0
}
increment() {
this.count += 1
}
render() {
return html`
<section class="card">
<div class="state">
<span>Shadow DOM state</span>
<strong>${this.count}</strong>
</div>
<button type="button" @click=${this.increment}>
Increment
</button>
</section>
`
}
}
customElements.define('counter-card', CounterCard)
Frequently asked questions
- Is the Lit playground free?
- Yes. The Lit playground is completely free with no sign-up — write, run and share Lit code in your browser.
- Do I need to install anything to run Lit online?
- No. The live preview compiles and runs in your browser. After downloading the project, install its dependencies before running it locally.
- Can I share or export my Lit code?
- Yes. Share creates a link to your project. Download exports a Vite project ZIP with its source files and package.json.
- Does the editor support autocomplete and live preview?
- It does — a Monaco-powered editor with autocomplete and formatting, a live preview that updates as you type, and a console for logs and errors.
compilebytes.com/tools/lit