Rehype FAQ
Short, accurate answers. Each links to a longer article where there is more to say.
What is rehype?
rehype is an open source JavaScript tool that processes HTML with plugins. It parses HTML into a syntax tree called hast, runs plugins that inspect or change the tree, and serializes the result back to HTML. It is part of the unified collective, alongside remark (Markdown) and retext (natural language). Start with What is rehype?
How do I install rehype?
In a Node.js project, run npm install rehype, then import {rehype} from 'rehype' in an ES module. For the terminal, install rehype-cli. See installation.
Is there a rehype app or .exe download?
No. rehype is a library, distributed through npm. The GitHub repository offers source code, which is not an installer. The download page explains the options.
Is rehype free?
Yes. rehype is released under the MIT License. Most plugins are MIT or ISC licensed; check each plugin's license before use.
Why do I get "does not provide an export named default"?
rehype has no default export. Write import {rehype} from 'rehype' with curly braces. Plugins such as rehype-sanitize are the opposite: they use a default export. More fixes are in troubleshooting.
Can I use rehype with CommonJS require()?
rehype is ESM only. Node.js 20.19 and later, and 22.12 and later, can require() ES modules without a flag, and in our tests on Node.js 22 require('rehype') worked. On older versions it throws ERR_REQUIRE_ESM; use import, or a dynamic import() from CommonJS.
What is the difference between rehype and remark?
remark works with Markdown and its tree format, mdast. rehype works with HTML and hast. The bridge plugins remark-rehype and rehype-remark convert between them. Read rehype vs remark.
Does rehype make HTML safe automatically?
No. Parsing and serializing keep scripts and event handlers. Use rehype-sanitize whenever the HTML comes from users or other untrusted sources, and run it after plugins that add markup you do not control.
Does rehype work in the browser?
Yes. The packages run in browsers when bundled; the tools on this site do exactly that. For smaller bundles with trusted content, the official rehype-dom packages parse and serialize with browser DOM APIs instead of parse5.
Are the online tools private?
Yes. The tools run rehype in a Web Worker in your browser. What you paste is not sent to this website or any other server. See the privacy policy.
How do I use rehype plugins with MDX or Next.js?
Pass them in the rehypePlugins option of @mdx-js/mdx, or in the options of createMDX from @next/mdx. The MDX and Next.js tutorial shows tested configuration.
Which rehype plugin should I use for syntax highlighting?
rehype-highlight (highlight.js grammars) is simple and fast. rehype-starry-night uses TextMate grammars for GitHub-like output. Shiki-based options such as rehype-pretty-code are popular in the community. Compare them in the Plugin Explorer.
How do I report a bug in rehype?
Report bugs to the official project, not to this site. The rehype repository on GitHub links to the support and contributing guidelines of the rehypejs organization; please read them before opening an issue.
Still stuck? Check troubleshooting or search the site.