How to Convert Markdown to HTML: A Complete Guide
How to Convert Markdown to HTML
Markdown is designed for writing, but the web runs on HTML. Every Markdown document needs conversion to HTML before a browser can display it. This guide covers the major methods for converting Markdown to HTML.
Method 1: Command-Line Tools
Pandoc
Pandoc is the universal document converter supporting dozens of formats.
# Basic conversion
pandoc input.md -o output.html
# Standalone HTML with <html> and <body> tags
pandoc input.md -o output.html -s
# With table of contents
pandoc input.md -o output.html -s --toc
Python-Markdown
pip install markdown
python -m markdown input.md > output.html
import markdown
with open("input.md", "r") as f:
text = f.read()
html = markdown.markdown(text, extensions=["fenced_code", "tables"])
CommonMark (JavaScript)
npm install commonmark
const commonmark = require("commonmark");
const reader = new commonmark.Parser();
const writer = new commonmark.HtmlRenderer();
const parsed = reader.parse("# Hello\nThis is **bold**.");
const html = writer.render(parsed);
Method 2: Static Site Generators
Jekyll
Jekyll powers GitHub Pages. It converts Markdown files from _posts or collections into HTML.
gem install jekyll bundler
jekyll new my-site
jekyll build
jekyll serve
Uses the Kramdown processor with Liquid templates for dynamic content.
Hugo
Hugo is a Go-based static site generator known for millisecond build speeds.
hugo new site my-site
hugo new posts/my-first-post.md
hugo server -D
Uses Goldmark as its default Markdown renderer with support for tables, fenced code blocks, and footnotes.
Next.js (MDX)
Next.js supports MDX, embedding React components inside Markdown.
npm install next @next/mdx @mdx-js/loader
MDX lets you include live code examples, charts, and forms in documentation.
Method 3: Online Converter
For one-off conversions without installing tools, browser-based converters provide instant results:
- Paste or type Markdown into the editor panel.
- The HTML output appears in real time.
- Copy the generated HTML for use in any web page or CMS.
The Markdown preview tool processes GitHub Flavored Markdown — tables, code blocks, task lists, and strikethrough — entirely in your browser.
Method 4: Editor Plugins
| Editor | Feature | Command |
|--------|---------|---------|
| VS Code | Built-in preview | Ctrl+Shift+V |
| Sublime Text | MarkdownPreview | Alt+M |
| IntelliJ IDEA | Built-in support | Quick Documentation |
| Vim | vim-markdown | :MarkdownPreview |
The Processing Pipeline
When a static site generator converts Markdown to HTML, it follows this pipeline:
Markdown → Parse to AST → Apply extensions → Render to HTML → Apply template → Output page
If a feature does not render as expected, the problem is usually at the parser (it does not support the syntax) or the renderer (it outputs unexpected HTML).
Convert Markdown to HTML Online
Use the Markdown preview tool to convert Markdown to HTML instantly. Type or paste Markdown in the editor, and the rendered preview updates in real time.