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.
Escaping Behavior
Thehtml 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, thehtml 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)
Use Cases
Building Components
Conditional Rendering
Lists
Security
Thehtml helper provides automatic XSS protection by escaping all interpolated values by default. Only use raw() when you are certain the content is safe.