HTML
An XSS-safe tagged template for building HTML strings. Interpolated values are HTML-escaped by default, making the safe path the default and explicit opt-in required for raw markup.
Basic usage
Interpolation rules
Escaping
All string and number interpolations are escaped automatically:
The characters &, <, >, ", and ' are all escaped.
Skipping null and undefined
null and undefined are silently omitted, making conditional rendering clean:
Trusted markup with raw()
When you need to inject pre-sanitized or server-controlled markup, use raw() to opt out of escaping:
Only use raw() with markup you fully control. Never pass user input to raw().
Nesting html`` results
Results of html`` are already safe and pass through unescaped when interpolated into a parent template. This is the foundation of composable templates:
Signal accessors
Signal accessors can be interpolated without calling them. ilha detects signal accessors and calls them automatically, then escapes the result:
Both forms are equivalent. The no-call shorthand is purely a convenience.
List rendering
Arrays are processed recursively with no comma joining. The canonical list pattern is:
Each html`` result in the array passes through unescaped. Mixed arrays of strings and html`` results also work — each item is processed by its own rules.
Whitespace and indentation
html\`` automatically strips leading and trailing blank lines and dedents the template based on the minimum indentation found. This keeps rendered output clean regardless of how the template is indented in source:
Return type
html`` returns a RawHtml object, not a plain string. This lets ilha distinguish between trusted and untrusted content when the result is interpolated into another template. To get the plain string value, access .value or let ilha unwrap it at a render boundary:
In practice you rarely need to access .value directly — ilha handles unwrapping automatically at render time.
Notes
- html`` is purely a runtime helper with no compiler step. It works in any JavaScript environment including Node, Bun, Deno, and the browser.
- Do not use html`` for CSS or attribute values where HTML escaping is not appropriate. Use the css`` tag for stylesheets and plain template literals for everything else.