Skip to content

escapeHtml

escapeHtml(value): string

Defined in: packages/core/src/utils/html.ts:42

Escape a value for interpolation into HTML, in text or attribute position.

ParameterType
valueunknown

string

Quotes are escaped, so the result is safe inside attr="..." and attr='...' as well as between tags. A single regex pass avoids the double-escaping bug that chained .replace() calls hit when & is not handled first.

Works without a DOM, so it is usable during SSR and in Node — the document.createElement trick it replaces was not.