- Category
- Document & metadata
- Maintained by
- rehype team
- License
- MIT
- Module format
- ESM, default export
npm install rehype-documentWhat it does
Pipelines that start from Markdown or from an HTML snippet produce a fragment. rehype-document wraps that fragment in <!doctype html>, <html>, <head> and <body>, adds a charset, a viewport meta tag and a title, and can link stylesheets and scripts.
Example
import {rehype} from 'rehype'
import rehypeDocument from 'rehype-document'
import rehypeFormat from 'rehype-format'
const file = await rehype()
.data('settings', {fragment: true})
.use(rehypeDocument, {title: 'Report', css: '/styles.css'})
.use(rehypeFormat)
.process('<h1>Monthly report</h1>')
console.log(String(file))<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Report</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="/styles.css" rel="stylesheet">
</head>
<body>
<h1>Monthly report</h1>
</body>
</html>Options
title: document title (defaults to the file name when there is one).lang(default'en') anddir('auto','ltr'or'rtl').cssandjs: URLs for<link>and<script src>elements.styleandscript: inline CSS and JavaScript source.metaandlink: extra<meta>and<link>elements.responsive(defaulttrue): whether to add the viewport meta tag.
Pair it with rehype-format for readable output, as in the example. The upstream rehype-meta plugin can add Open Graph and other metadata to the head.
Official references
- rehype-document readme (API and all options) (opens in a new tab)
- rehype-document on npm (current version) (opens in a new tab)
Facts on this page were checked against the package readme on November 11, 2026. Options not covered here are documented upstream.