> For AI agents: the complete documentation index is available at https://rspack.rs/llms.txt, the full documentation bundle is available at https://rspack.rs/llms-full.txt.

# HTML

Rspack can generate HTML through plugins and automatically inject emitted JavaScript and CSS assets. This guide covers two plugin options and how they differ in performance, features, and `html-webpack-plugin` compatibility.

## Choose a plugin

Rspack provides two plugin options for generating HTML:

- The built-in [`rspack.HtmlRspackPlugin`](https://rspack.rs/plugins/html-rspack-plugin.md) is implemented in Rust and focuses on performance and common HTML generation needs.
- The standalone [`html-rspack-plugin`](https://github.com/rstackjs/html-rspack-plugin) is a JavaScript fork of `html-webpack-plugin` that prioritizes compatibility with its behavior.

### Performance

The built-in Rust implementation provides better build performance, especially when generating many HTML files. The JavaScript plugin also includes Rspack-specific optimizations but prioritizes compatibility.

### Features

`rspack.HtmlRspackPlugin` supports most `html-webpack-plugin` features, but cannot fully match all behaviors of the JavaScript implementation because its core logic runs in Rust. Use it when its features meet your needs and performance is the priority. Use `html-rspack-plugin` when migrating an existing `html-webpack-plugin` setup or when you need an unsupported option, capability, or behavior.

:::tip
`rspack.HtmlRspackPlugin` supports only a subset of EJS-style syntax and does not execute arbitrary JavaScript. For compatibility with `html-webpack-plugin` template processing behavior, use `html-rspack-plugin` and see its [template documentation](https://github.com/rstackjs/html-rspack-plugin#writing-your-own-templates).
:::

## Built-in HtmlRspackPlugin

`rspack.HtmlRspackPlugin` is included in `@rspack/core`, so no additional package is required.

```js title="rspack.config.mjs"
import { rspack } from '@rspack/core';

export default {
  plugins: [new rspack.HtmlRspackPlugin()],
};
```

For all configuration options, see the [plugin documentation](https://rspack.rs/plugins/html-rspack-plugin.md).

## html-rspack-plugin

Install `html-rspack-plugin` separately:


```sh [npm]
npm add html-rspack-plugin -D
```

```sh [yarn]
yarn add html-rspack-plugin -D
```

```sh [pnpm]
pnpm add html-rspack-plugin -D
```

```sh [bun]
bun add html-rspack-plugin -D
```

```sh [deno]
deno add npm:html-rspack-plugin -D
```

```js title="rspack.config.mjs"
import HtmlRspackPlugin from 'html-rspack-plugin';

export default {
  plugins: [new HtmlRspackPlugin()],
};
```

For configuration options, see [Options](https://github.com/rstackjs/html-rspack-plugin#options).

If you are migrating from `html-webpack-plugin`, see the [webpack migration guide](https://rspack.rs/guide/migration/webpack.md#html-webpack-plugin).
