A helper for creating a DocumentFragment in JavaScript


html(strings, substitutions) method

A JavaScript template string literal that returns an HTML document fragment.


const fragment = html`Hello, <em>world</em>.`

returns a DocumentFragment whose innerHTML is Hello, <em>world</em>.

This function is called html so that it can be easily used with HTML syntax-highlighting extensions for various popular code editors.

See also template.html, which returns a similar result but as an HTMLTemplateElement.


  • strings: TemplateStringsArraythe strings passed to the JavaScript template literal
  • substitutions: Array.the variable values passed to the JavaScript template literal

Returns: DocumentFragment