# @remix-run/html-template

> HTML template tag with auto-escaping for JavaScript

Latest version **1.0.0** (published 2026-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @remix-run/html-template
pnpm add @remix-run/html-template
yarn add @remix-run/html-template
bun add @remix-run/html-template
```

## Health

**Score 70/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2026-10-01 |
| First published | 2025-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 14.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 33456 |
| Author | Michael Jackson |
| Maintainers | mjackson |
| Keywords | html, template, tagged-template, template-literal, safe-html, xss, escaping, sanitize, security |

## Links

- npm: https://www.npmjs.com/package/@remix-run/html-template
- Repository: https://github.com/remix-run/remix
- Homepage: https://github.com/remix-run/remix/tree/main/packages/html-template#readme
- Issues: https://github.com/remix-run/remix/issues
- npm.io page: https://npm.io/package/@remix-run/html-template

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2026-10-01
- 0.3.2 — 2026-09-28
- 0.3.1 — 2026-05-20
- 0.3.0 — 2025-11-05
- 0.2.0 — 2025-10-31
- 0.1.0 — 2025-10-26

## README

# html-template

Safe HTML template literals for Remix. `html-template` automatically escapes interpolated values to prevent XSS while still supporting explicit trusted HTML insertion.

## Features

- **Automatic HTML escaping** - All interpolated values are escaped by default
- **Explicit raw HTML** - Use `html.raw` when you need unescaped HTML from trusted sources
- **Composable** - SafeHtml values can be nested without double-escaping
- **Type-safe** - Full TypeScript support with branded types
- **Zero dependencies** - Lightweight and self-contained
- **Runtime agnostic** - Works in Node.js, Bun, Deno, browsers, and edge runtimes

## Installation

```sh
npm i remix
```

## Usage

```ts
import { html } from 'remix/html-template'

let userInput = '<script>alert("XSS")</script>'
let greeting = html`<h1>Hello ${userInput}!</h1>`

console.log(String(greeting))
// Output: <h1>Hello &lt;script&gt;alert("XSS")&lt;/script&gt;!</h1>
```

By default, all interpolated values are automatically escaped to prevent XSS attacks.

If you have trusted HTML that should not be escaped, use `html.raw`:

```ts
import { html } from 'remix/html-template'

let trustedIcon = '<svg>...</svg>'
let button = html.raw`<button>${trustedIcon} Click me</button>`

console.log(String(button))
// => <button><svg>...</svg> Click me</button>
```

**Warning**: Only use `html.raw` with content you trust. Never use it with user input.

### Composing HTML Fragments

SafeHtml values can be nested without double-escaping:

```ts
import { html } from 'remix/html-template'

let title = html`<h1>My Title</h1>`
let content = html`<p>Some content with ${userInput}</p>`

let page = html`
  <!doctype html>
  <html>
    <body>
      ${title} ${content}
    </body>
  </html>
`
```

### Working with Arrays

You can interpolate arrays of values, which will be flattened and joined:

```ts
import { html } from 'remix/html-template'

let items = ['Apple', 'Banana', 'Cherry']
let list = html`
  <ul>
    ${items.map((item) => html`<li>${item}</li>`)}
  </ul>
`
```

### Conditional Rendering

Use `null` or `undefined` to render nothing:

```ts
import { html } from 'remix/html-template'

let showError = false
let errorMessage = 'Something went wrong'
let page = html`<div>${showError ? html`<div class="error">${errorMessage}</div>` : null}</div>`
```

## Related Packages

- [`remix/router`](https://github.com/remix-run/remix/tree/main/packages/fetch-router) - HTTP router that works great with html-template

## License

See [LICENSE](https://github.com/remix-run/remix/blob/main/LICENSE)

---
_Source: https://npm.io/package/@remix-run/html-template · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
