For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/languages/html.md.
close

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 is implemented in Rust and focuses on performance and common HTML generation needs.
  • The standalone 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.

Built-in HtmlRspackPlugin

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

rspack.config.mjs
import { rspack } from '@rspack/core';

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

For all configuration options, see the plugin documentation.

html-rspack-plugin

Install html-rspack-plugin separately:

npm
yarn
pnpm
bun
deno
npm add html-rspack-plugin -D
rspack.config.mjs
import HtmlRspackPlugin from 'html-rspack-plugin';

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

For configuration options, see Options.

If you are migrating from html-webpack-plugin, see the webpack migration guide.