Documentation menu
Install Rehype
rehype runs on Node.js and is installed with a package manager. Choose the option that matches what you want to do.
Install with npm
Use rehype in JavaScript code: scripts, build steps, servers and static site generators.
Install rehype-cli
Process HTML files from the terminal or npm scripts without writing code.
Requirements
- Node.js. The rehype readme says the current release line is kept compatible with Node.js 16 and later, and that unified projects support maintained Node.js versions. Use a current LTS release of Node.js; the examples on this site were run with Node.js 22.
- A package manager. npm ships with Node.js. pnpm, Yarn and Bun can install the same packages.
- ES modules. rehype and its plugins are ESM only. Use
importin.mjsfiles or set"type": "module"inpackage.json.
Check what you have:
node --version
npm --versionQuick start
mkdir rehype-demo && cd rehype-demo
npm init -y
npm pkg set type=module
npm install rehype rehype-formatSave this as example.js and run node example.js:
import {rehype} from 'rehype'
import rehypeFormat from 'rehype-format'
const input = `<!doctype html><html lang=en><head><title>Demo</title></head>
<body><main><h1>Hello</h1><p>Formatted by <b>rehype</b>.</p></main></body></html>`
const file = await rehype().use(rehypeFormat).process(input)
console.log(String(file))<!doctype html>
<html lang="en">
<head>
<title>Demo</title>
</head>
<body>
<main>
<h1>Hello</h1>
<p>Formatted by <b>rehype</b>.</p>
</main>
</body>
</html>Which package do I need?
| Package | Contains | Install when |
|---|---|---|
rehype | unified + rehype-parse + rehype-stringify | HTML in, HTML out (the common case) |
rehype-parse | HTML parser plugin | HTML in, something else out (for example Markdown) |
rehype-stringify | HTML serializer plugin | Something else in (for example Markdown via remark), HTML out |
rehype-cli | The rehype command | Working with files from a terminal |
Not sure what the source code download is for? See Download Rehype.