html tag. Dynamic values are inserted using JavaScript expressions inside ${} placeholders. The position of an expression in the template determines what kind of binding is created.
Child content expressions
An expression in the text content of an element creates a child part — a dynamic text node or subtree in the DOM.Nested templates
You can nesthtml template results inside other templates. Lit efficiently updates the nested content in place when it re-renders.
Arrays and iterables
Any iterable — includingArray, Set, generator functions, and the results of directives like map() or repeat() — can be used in a child expression. Each item is rendered in order.
Attribute binding
An expression inside an attribute value (using double quotes) creates an attribute part. The value is coerced to a string and set as the attribute.Attribute bindings set the HTML attribute — the string representation. To set
a DOM property directly, use a property binding instead.
Boolean attribute binding
Prefix the attribute name with? to create a boolean attribute part. The attribute is added when the value is truthy and removed when it is falsy.
Property binding
Prefix the attribute name with. to create a property part. The value is assigned directly to the DOM property instead of setting an HTML attribute.
Event listener binding
Prefix the attribute name with@ to create an event part. The value is added as an event listener for the named event.
addEventListener and removed automatically when the binding changes. When you render a component method as the listener, Lit binds the listener to the component’s host option so this refers to the component instance.
Element reference binding
An expression placed directly on an element tag (not in an attribute) creates an element part. Theref() directive uses element parts to get a reference to the rendered element.
Renderable values
The following types are valid in child expressions:| Value type | Behavior |
|---|---|
string, number, bigint, boolean | Rendered as a text node |
TemplateResult (from html, svg, mathml) | Rendered as DOM nodes |
DirectiveResult | Handled by the directive |
Array / Iterable | Each item rendered in sequence |
Node | Inserted directly into the DOM |
undefined, null, '' | Renders nothing (no DOM node) |
nothing | Renders nothing (preferred over null/undefined) |
noChange | Leaves the current DOM value unchanged |
Sentinels: nothing and noChange
Lit exports two special sentinel values from lit:
nothing
Signals that a child part should render no content, or that an attribute should be removed.
- Child expression — renders no DOM nodes (same as
null,undefined, or'') - Attribute binding — removes the attribute from the element
- Property binding — sets the property to
undefined - Boolean attribute — removes the attribute
noChange
Signals that a value was handled by a directive and the DOM should not be updated. You will not typically use noChange in application code — it is used internally by directives.
Static expressions
Regular expressions cannot be used for tag names or attribute names because Lit parses the template strings once and reuses the parsed structure. To include dynamic tag names or attribute names you must usestaticHtml and literal from lit/static-html.js.