Markdown is great for writing, but the people you send a document to often expect a web page or a PDF. Luckily, converting Markdown is easy, and most cases need no complex toolchain.
Below are four ways to do it, from the quickest to the most configurable, and a set of tips that make the output look professional.
Quick comparison
| Method | HTML | Install | Best for | |
|---|---|---|---|---|
| Browser editor export | ✅ | ✅ (print) | Nothing | Everyday documents, quick sharing |
| VS Code + extension | ✅ | ✅ | Editor + extension | People who already write in VS Code |
| Pandoc | ✅ | ✅ | Pandoc (+ a PDF engine) | Books, papers, automated pipelines |
| A script (markdown-it, marked) | ✅ | — | Node.js | Custom websites and build steps |
1. Export from a browser-based editor
The quickest route is an editor with a built-in export. In Markdown Preview Editor open or paste your document — from the online version or your own copy — and use the buttons in the header:
- HTML creates a single self-contained
.htmlfile. Styles, code highlighting, formulas, diagrams and images you opened together with the document are embedded, so the file looks right on any computer and can be attached to an email or uploaded anywhere as is. - Print opens the browser’s print dialog. Choose Save as PDF as the destination to get a PDF. Only the rendered document is printed — no toolbar, no editor.
- Save downloads the Markdown source as a
.mdfile.
Because everything happens in the browser, this also works for documents you’d rather not upload to an online converter.
Getting a clean PDF from the print dialog
- Set Margins to Default or Minimum, depending on how much text you want per page.
- Turn Headers and footers off to remove the date and URL from the page edges.
- Turn Background graphics on if you want code block backgrounds and table stripes.
- Use a light theme for printing — it saves ink and is easier to read on paper.
2. VS Code with an extension
VS Code has a built-in Markdown preview but no export button. Extensions such as Markdown PDF or Markdown Preview Enhanced add commands to export HTML and PDF. This is convenient if VS Code is already your editor; the output styling depends on the extension, and some of them download a headless browser on first use.
3. Pandoc — the universal converter
Pandoc converts between dozens of formats and is the standard tool for books, academic papers and automated documentation. After installing it, conversion is a single command:
bash# Markdown to a complete HTML page
pandoc report.md -o report.html --standalone --metadata title="Report"
# Markdown to PDF (needs a PDF engine, e.g. a LaTeX distribution)
pandoc report.md -o report.pdf --pdf-engine=xelatex
# Markdown to Word, if someone insists
pandoc report.md -o report.docx
Without --standalone, Pandoc outputs only an HTML fragment — handy if you insert it into an existing page. PDF output requires a separate engine: a LaTeX distribution, or an HTML-based engine such as WeasyPrint. Where Pandoc shines is control: templates, citations, numbered sections and cross-references.
4. A few lines of JavaScript
If Markdown is part of your own website or build process, a library is the most flexible option. With markdown-it:
jsimport MarkdownIt from 'markdown-it';
import { readFileSync, writeFileSync } from 'node:fs';
const md = new MarkdownIt({ linkify: true, typographer: true });
const body = md.render(readFileSync('README.md', 'utf8'));
writeFileSync('README.html', `<!doctype html><meta charset="utf-8"><title>README</title>${body}`);
Plugins add footnotes, task lists, math and more. Remember that the output is only as safe as its input: if the Markdown comes from other people, sanitize the HTML (for example with DOMPurify) before you publish it.
Tips for better HTML and PDF output
Start with one clear title
Converters take the document title from the file name, the first heading or explicit metadata. Give every document a descriptive file name and a single # heading, and the exported HTML and PDF will be easy to recognize in a downloads folder or a browser tab.
Keep images next to the document
Use relative paths like images/chart.png and keep the files in the same folder. When you open the whole folder in Markdown Preview Editor, the images are resolved and embedded into the HTML export. Remote images that are not loaded in the preview are not embedded either.
Control page breaks
Markdown has no page-break syntax. For printed documents, start big sections with a ## heading and keep tables short — browsers avoid splitting table rows, but a huge table will still continue on the next page. In tools that allow raw HTML and inline styles, such as Pandoc, you can insert <div style="page-break-after: always"></div>.
Check formulas and diagrams before exporting
Math and diagrams are rendered by JavaScript libraries in most tools. Check them in the preview first — see our guides to math equations in Markdown and Mermaid diagrams. In Markdown Preview Editor’s HTML export they are stored as ready-made markup and images, so the exported file doesn’t need any scripts.
Choose the theme on purpose
Dark HTML exports look good on screen but work poorly on paper. Export for the medium the reader will use.
Frequently asked questions
How do I convert Markdown to PDF for free?
Open the document in a Markdown previewer such as Markdown Preview Editor, click Print and choose Save as PDF in the print dialog. For automated or book-style output, use the free Pandoc command-line tool.
How do I convert Markdown to HTML without installing anything?
Use a browser-based editor with an HTML export. Markdown Preview Editor creates a self-contained HTML file with the styles included, directly in your browser.
Will images be included in the exported HTML?
Local images you opened together with the document are embedded into the HTML file, so it works on its own. Images that stay on remote servers are not embedded.
Can I convert Markdown to Word (DOCX)?
Yes, with Pandoc: pandoc input.md -o output.docx. Alternatively, export HTML and open it in Word, which keeps most of the formatting.