Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
ES6 tagged template for compiling HTML strings with automatic escaping and pre-compiling support.
html-template-tag is a small open-source npm package that provides an ES6 tagged template function for compiling and escaping HTML strings in JavaScript. It takes a template literal with interpolated expressions and returns a string where HTML special characters are automatically escaped, making it useful for safe server-rendered HTML.
html-template-tag is a standalone JavaScript utility published on npm under the name html-template-tag. It implements a tagged template function that you place before a template literal, so `${name}` becomes the escaped value of the name variable rather than JavaScript string concatenation. The package runs in Node.js and can be imported with either CommonJS require or ES6 import. It is available from the GitHub repository AntonioVdlC/html-template-tag and is licensed under MIT.
<, >, &, and quote characters in every interpolated value, preventing XSS from user-provided strings..map() inside the template and produce repeated elements with correctly escaped content.`$${value}` inserts a value without escaping, allowing intentional raw HTML if you trust the source.href are removed or escaped to block common XSS attack vectors; the README links to the OWASP XSS Filter Evasion Cheat Sheet.npm install html-template-tag.const html = require('html-template-tag') or import html from 'html-template-tag'.html tag before a template literal; any `${expression}` is escaped, while `$${expression}` is inserted raw.The README provides working examples of string interpolation, loop usage, pre-compiling templates, and URI attribute interpolation.
Yes, it is open-source and distributed under the MIT license, so it can be used in both personal and commercial projects without cost.
It is a generic JavaScript tagged template and is not tied to any framework. It works wherever you can write ES6 template literals, but it does not provide React components or hooks.
Use double dollar signs: in a template literal, write `$${value}` instead of `${value}`. The content will be inserted without escaping, so only use it with trusted strings.
The implementation escapes HTML special characters including <, >, &, and quotes. The exact set covers the characters needed to neutralize XSS in text content and attributes.