---
url: https://void.cloud/reference/api/html.md
description: Use HTML templates in route handlers and generated images.
---

# HTML Templates

Use `html` from `void/html` to put dynamic text in markup. For example, this route displays a greeting:

```ts
import { defineHandler } from 'void';
import { html } from 'void/html';

export const GET = defineHandler(async (c) => {
  const name = c.req.query('name') ?? 'World';
  return c.html(await html`<h1>Hello ${name}</h1>`);
});
```

## `html` {#html}

For `?name=<b>World</b>`, the heading displays `Hello <b>World</b>` as text. Strings are escaped, including quotes. Nested templates keep their markup, and you can interpolate promises:

```ts
import { html } from 'void/html';

const heading = html`<h1>${Promise.resolve('Hello <World>')}</h1>`;
const page = await html`<main>${heading}</main>`;
```

The tag returns `HtmlEscapedString | Promise<HtmlEscapedString>`. Await it for `c.html()`. [Image responses](../../guide/image-generation.md) accept either form directly.

## `raw(value)` {#raw}

Use `raw` for a string you trust and want to render as HTML. For user input, interpolate the string directly into `html` so it stays text.

```ts
import { html, raw } from 'void/html';

const greeting = raw('<strong>Hello</strong>');
const page = html`<main>${greeting}</main>`;
```

## `HtmlEscapedString`

Import `HtmlEscapedString` from `void/html` to type a helper that accepts or returns a template. Include `Promise<HtmlEscapedString>` if the template can contain async values.
