---
description: 'Generate PNGs from HTML or JSX in a route handler.'
outline: deep
---
# Image Generation
Return an `ImageResponse` from a route to draw a PNG with HTML and CSS.
## Draw a badge {#usage}
Read the badge label from the URL and put it in an `html` template:
```ts
// routes/badge.png.ts
import { defineHandler } from 'void';
import { html } from 'void/html';
import { ImageResponse } from 'void/image';
export const GET = defineHandler((c) => {
const label = c.req.query('label') ?? 'Built with Void';
return new ImageResponse(
html`
${label}
`,
{ width: 320, height: 64 },
);
});
```
Open `/badge.png?label=Preview` to see a 320 × 64 badge that reads “Preview”. The [`html` tag](../reference/api/html.md) escapes the label, so text like `` appears as written. For a social preview, use [`OgImageResponse`](./og-images.md) to get the standard 1200 × 630 size.
## Rendering with JSX {#jsx-types}
To draw a favicon with Hono JSX, add `/** @jsxImportSource void/jsx */` at the top of the `.tsx` route. This works alongside a React, Vue, Svelte, or Solid app without changing how your pages render.
```tsx
/** @jsxImportSource void/jsx */
// routes/favicon.png.tsx
import { ImageResponse } from 'void/image';
export const GET = () =>
new ImageResponse(
V
,
{ width: 64, height: 64 },
);
```
To use Hono JSX for every `.tsx` file, set `jsxImportSource` in your [TypeScript and Vite config](./server-routing.md#jsx-handlers). Image routes accept Hono elements and `html` templates, including async templates. Use `ImageInput` to type shared card content.
## Where images render {#setup}
Void uses local Chromium in development, preview, and [prerendering](./edge/prerendering.md). Importing `void/image` adds a Browser Run binding named `BROWSER` for deployment.
- **Your Cloudflare account:** `void deploy --platform cloudflare` uses your account’s [Browser Run allowance](https://developers.cloudflare.com/browser-run/limits/). [Quick Actions](https://developers.cloudflare.com/browser-run/quick-actions/) require a Worker compatibility date of `2026-03-24` or later. If your app pins an older date, update `worker.compatibility_date` in `void.config.ts`.
- **A Void platform:** each render counts toward your account’s [monthly browser time](./platform/administration/plans.md) and your app’s request rate. The binding supports Quick Actions on the default browser, except `json`. For Browser Sessions, deploy to your own Cloudflare account. If the platform predates Browser Run support, ask its administrator to upgrade before deploying.
To test against your Cloudflare account during development, run `void connect --platform cloudflare` and set `remote: true`:
```ts
// void.config.ts
import { defineConfig } from 'void/config';
export default defineConfig({
cloudflare: { browser: { binding: 'BROWSER', remote: true } },
});
```
## Await rendering
Use `renderImage()` when you need the PNG bytes, for example to save the badge to storage or return a fallback if rendering fails:
```ts
import { html } from 'void/html';
import { renderImage } from 'void/image';
export function renderBadge(label: string) {
return renderImage(html`${label}`, { width: 320, height: 64 });
}
```
Call `await renderBadge(label)` in your handler to catch a rendering error before sending headers. An `ImageResponse` starts rendering when its body is read, after the handler has returned. In a Void handler or Pages action, an uncaught `UsageLimit` from `void/limits` returns HTTP 429. A platform rate limit includes `retryAt`. A monthly quota resets at the next billing period.
## Options
For shared options, import `RenderImageOptions` or `ImageResponseOptions` from `void/image`.
| Option | Behavior |
| --------------------------------- | ------------------------------------------------------------------------------------ |
| `width`, `height` | Required image dimensions in pixels. Use positive integers. |
| `font`, `fonts` | Select a font family or fallback stack and supply custom faces. See [Fonts](#fonts). |
| `lang` | Set the document language, for example `'ja'`. |
| `debug` | Set to `true` to outline each element. |
| `status`, `statusText`, `headers` | HTTP options for `ImageResponse`. The content type defaults to `image/png`. |
### CSS and images
Use inline CSS or a `