Documentation menu
Rehype documentation
Practical documentation for rehype, with tested examples. For the authoritative API reference, the official readmes on GitHub remain the source of truth; we link to them throughout.
Start here
Install
Requirements, npm and CLI setup.
Getting started
Install rehype, run your first pipeline, add plugins and process fragments and files, with tested code at every step.
How rehype works
The unified processor, the three phases of processing, the hast tree format, virtual files and where plugins plug in.
Troubleshooting
The errors and surprises developers hit most often with rehype, with the exact message and the fix.
Tutorials by topic
What Is Rehype? A Practical Introduction
What rehype is, the problems it solves, how it fits into unified, and when it is the right tool.
Rehype vs Remark: Key Differences and Use Cases
rehype handles HTML, remark handles Markdown. How they differ, and how to move content between them in one pipeline.
Rehype Parse and Stringify Explained
The parser and serializer at the heart of rehype: fragments, parse errors, and the options that change the output.
Rehype Plugins: How to Choose and Use Them
How to find and evaluate plugins, install and configure them, and order them so they do not undo each other.
Sanitize HTML safely with rehype-sanitize
Use rehype-sanitize to neutralize XSS in user content: schemas, plugin order, DOM clobbering and the mistakes to avoid.
Syntax highlighting with rehype-highlight
Highlight code at build time from HTML or Markdown, style it with a theme, keep bundles small and stay safe with sanitizing.
Heading ids and anchor links with rehype-slug
Generate stable heading ids, add accessible anchor links, handle duplicates and prefixes, and collect a table of contents.
Format and minify HTML with rehype
Pretty-print HTML with rehype-format for humans and minify it with rehype-preset-minify for production, in code or from the CLI.
Build Your First Rehype Plugin
Write two real plugins: one that changes the tree (lazy images) and one that reports problems (missing alt text).
Using rehype plugins with MDX and Next.js
Pass rehype plugins to MDX and to Next.js through the rehypePlugins option, including the Turbopack-compatible string syntax.