Tagged template literal for trusted HTML content.
Performance: Zero-copy for static templates, optimized fast paths for single-value interpolation. String cache reduces repeated normalization overhead.
Behavior:
[1,2,3]
"123"
0
safeHtml
const name = 'Alice';html`<h1>Hello, ${name}!</h1>`// "<h1>Hello, Alice!</h1>" Copy
const name = 'Alice';html`<h1>Hello, ${name}!</h1>`// "<h1>Hello, Alice!</h1>"
const items = ['a', 'b', 'c'];html`<ul>${items.map(x => html`<li>${x}</li>`)}</ul>`// "<ul><li>a</li><li>b</li><li>c</li></ul>" Copy
const items = ['a', 'b', 'c'];html`<ul>${items.map(x => html`<li>${x}</li>`)}</ul>`// "<ul><li>a</li><li>b</li><li>c</li></ul>"
const count = 0;html`<div>Count: ${count}</div>`// "<div>Count: 0</div>" (zero preserved) Copy
const count = 0;html`<div>Count: ${count}</div>`// "<div>Count: 0</div>" (zero preserved)
Static template parts
Rest
Dynamic values for interpolation
Rendered HTML string
Tagged template literal for trusted HTML content.
Performance: Zero-copy for static templates, optimized fast paths for single-value interpolation. String cache reduces repeated normalization overhead.
Behavior:
[1,2,3]
→"123"
0
safeHtml
for untrusted inputExample
Example
Example