Skip to content

html

Sets an element's innerHTML. Does not escape HTML — use with trusted content only.

Syntax

typescript
html`<div :html=${htmlString}></div>`
// or
applyProps(element, { innerHTML: htmlString });

Example

typescript
const content = "<h1>Welcome</h1><p>This is <strong>bold</strong>.</p>";

html`<div :html=${content}></div>`;
// Renders: <div><h1>Welcome</h1><p>This is <strong>bold</strong>.</p></div>

Security Warning

Never use :html with user-generated content. It can expose your application to XSS attacks. Use :text for untrusted content.

When to Use

  • Rendering sanitized HTML from a trusted source (e.g., a CMS)
  • Rendering HTML generated by a third-party library you control
  • Inline SVG or other markup that's not representable as text