Skip to main content
The HTML Helper provides a tagged template literal for creating HTML strings with automatic XSS protection through HTML escaping.

Import

Functions

html()

Creates an HTML string with automatic escaping of interpolated values.
TemplateStringsArray
required
The template string array
unknown[]
required
Values to interpolate into the template. All values are automatically HTML-escaped except those wrapped with raw().
HtmlEscapedString | Promise<HtmlEscapedString>
An HTML-escaped string. Returns a Promise if any interpolated value is a Promise.
Example

Escaping Behavior

The html helper automatically escapes the following:
  • Strings: HTML special characters are escaped (<, >, &, ", ')
  • Numbers: Rendered as-is
  • Booleans, null, undefined: Ignored (rendered as empty string)
  • Arrays: Flattened with Array.flat(Infinity) and each element is processed
  • Promises: Awaited and then processed
  • Objects: Converted to string via .toString() and escaped

Async Support

When interpolating Promises, the html function returns a Promise:

raw()

Marks a string as safe HTML that should not be escaped.
string
required
The HTML string that should not be escaped
HtmlEscapedString
An HTML string marked as safe (not escaped)
Example
Output:

Use Cases

Building Components

Conditional Rendering

Lists

Security

The html helper provides automatic XSS protection by escaping all interpolated values by default. Only use raw() when you are certain the content is safe.

Types