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:

  • Arrays flatten without separators: [1,2,3]"123"
  • Falsy values excluded except 0
  • Whitespace normalized between tags
  • No XSS protection - use safeHtml for untrusted input
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>"
const count = 0;
html`<div>Count: ${count}</div>`
// "<div>Count: 0</div>" (zero preserved)
  • Parameters

    • strings: TemplateStringsArray

      Static template parts

    • Rest...values: any

      Dynamic values for interpolation

    Returns string

    Rendered HTML string