Developer Guide
Convert Markdown to HTML with Pandoc
Convert Markdown to HTML with Pandoc from the command line. Run pandoc input.md -o output.html to produce an HTML file. Pandoc handles large documents, GitHub Flavored Markdown, and dozens of other input and output formats.
Key facts
- Command
- pandoc input.md -o output.html
- Standalone document
- -s flag adds <html>, <head>, <body>
- GitHub Flavored input
- -f gfm
- Install
- Homebrew, apt, or winget
How do you convert Markdown to HTML with Pandoc?
Run pandoc input.md -o output.html on the command line. Pandoc reads the Markdown file and writes the HTML file. The -o flag names the output; the input format is inferred from the .md extension.
Pandoc is a command-line tool, not a library, so it suits scripts and build pipelines. For the methods overview across languages and tools, see How to Convert Markdown to HTML.
pandoc input.md -o output.htmlHow do you produce a complete HTML document?
Add the -s (standalone) flag. Without it, Pandoc emits an HTML fragment with no wrapper. With -s, Pandoc wraps the output in a full document with <html>, <head>, and <body> elements ready to open in a browser.
The fragment form suits embedding inside an existing page; the standalone form suits a self-contained file.
pandoc input.md -s -o output.htmlHow do you convert GitHub Flavored Markdown?
Set the input format with -f gfm. This tells Pandoc to parse the source as GitHub Flavored Markdown, so tables, task lists, and strikethrough convert correctly instead of being treated as plain text.
Pandoc supports several Markdown dialects through the -f flag. For the GitHub Flavored feature set, see GitHub Flavored Markdown to HTML.
pandoc -f gfm input.md -o output.htmlHow do you apply a stylesheet?
Add -c style.css to link a stylesheet into a standalone document. Combine it with -s so the generated <head> includes the link. The CSS file is referenced, not inlined, in the output HTML.
pandoc -s -c style.css input.md -o output.htmlFrequently Asked Questions
- How do I install Pandoc?
- Install Pandoc with a package manager: brew install pandoc on macOS, sudo apt install pandoc on Debian or Ubuntu, or winget install JohnMacFarlane.Pandoc on Windows. Official installers are also available for each platform.
- What is the difference between a fragment and a full document?
- By default Pandoc outputs an HTML fragment with no <html> wrapper, meant for embedding. The -s flag produces a standalone document with <head> and <body>, meant to open directly in a browser.
- How do I convert many Markdown files at once?
- Loop over the files in your shell and run Pandoc on each. For example, a for loop calling pandoc on every .md file writes a matching .html file per document, which suits batch build scripts.
- What input formats does Pandoc support?
- Pandoc converts between dozens of formats, including Markdown, reStructuredText, HTML, LaTeX, and DOCX. This breadth is why it is often called a universal document converter, beyond Markdown to HTML alone.