Fragment or full page?
Decide first what the HTML is for, because it changes the output you want:
- An HTML fragment is only the converted content:
<h2>,<p>,<ul>,<table>. It is what you paste into a CMS, a blog editor's HTML view, an email template or a component. - A full HTML document wraps the content in
<html>,<head>and<body>, with a title and styles. It is what you send to someone, attach to an email or open from the desktop.
Most methods below can produce either.
Method 1: in your browser
For a one-off conversion, a browser converter is quickest and needs nothing installed.
- Paste the Markdown into the Markdown to HTML converter, or open a .md file.
- Leave Full HTML document off for a fragment, or turn it on for a standalone page with a small stylesheet.
- Use the HTML / Preview toggle to check the result, then Copy HTML or Download .html.
It supports GitHub Flavored Markdown: tables with alignment, task lists, strikethrough, footnotes and fenced code blocks with a language class for a syntax highlighter.
Method 2: Pandoc on the command line
Pandoc is the standard tool for scripts and batches:
pandoc notes.md -f gfm -o notes.htmlThat gives a fragment. For a full page, add --standalone (or -s) and a title:
pandoc notes.md -f gfm -s --metadata title="Notes" -o notes.htmlTo include a stylesheet and the images inside that single page, so you can email it, add --css style.css --embed-resources to the --standalone command. Pandoc also has options for a table of contents (--toc) and math (--mathml or --katex).
Method 3: in code
When Markdown is converted inside an app or a build step, use a library.
JavaScript, with marked:
import { marked } from "marked";
const html = marked.parse("# Hello\n\nSome **bold** text.");Other common choices are markdown-it, and unified with remark and rehype when you need plugins that change the document tree.
Python, with Python-Markdown:
import markdown
html = markdown.markdown(text, extensions=["tables", "fenced_code"])Libraries differ in which extensions they support out of the box. Check tables, task lists and footnotes with your own content.
Method 4: export from a Markdown app
Many Markdown apps export HTML from a menu. Typora and Marked export HTML; in VS Code, an extension such as Markdown All in One adds an HTML export command. Aero Markdown for Mac exports the open document as one local HTML file with its stylesheet and local PNG, JPEG, GIF and WebP pictures embedded, so it opens without the Markdown folder; Mermaid and math stay as source because the file contains no scripts. See exporting Markdown as HTML for a handoff for what to check before you send the file.
Which method to use
| Need | Best method |
|---|---|
| Paste one document into a CMS or email | Browser converter, fragment |
| Send a page to someone | Browser converter or app export, full document |
| Convert many files, or in a script | Pandoc |
| Render Markdown inside your own app or site | A library, with sanitizing |
| One file with its pictures inside | Pandoc with --embed-resources, or an app export |
Keep it safe
Markdown allows raw HTML, and converters keep it by default. That's useful for your own documents and dangerous for anyone else's: a comment, an issue or an uploaded file can contain <script> tags, javascript: links or event handlers that run when the HTML is shown.
If the Markdown comes from other people, sanitize the HTML after converting, with a library such as DOMPurify in the browser or rehype-sanitize in a unified pipeline, or turn raw HTML off in the converter. The preview in the browser converter above, for example, removes raw HTML and unsafe links, while the HTML code it gives you keeps your HTML as written.
Going the other way
To turn HTML, a web page or a Google Doc back into Markdown, use the HTML to Markdown converter, or see how to save a web page as Markdown.
Frequently asked questions
How do I convert Markdown to HTML?
Paste the Markdown into a converter such as the free Markdown to HTML tool on aeromarkdown.app and copy the HTML. From the command line, run pandoc input.md -f gfm -o output.html. In code, use a library such as marked or markdown-it in JavaScript, or Python-Markdown.
What is the difference between an HTML fragment and a full HTML document?
A fragment is only the converted content, such as headings, paragraphs and lists, ready to paste into a CMS, a template or an email. A full document adds the html, head and body tags, a title and usually a stylesheet, so it opens as a page on its own.
Is HTML generated from Markdown safe?
Only if the Markdown is trusted. Markdown allows raw HTML, so a converter can pass a script or an unsafe link straight into the output. Sanitize the HTML, for example with DOMPurify or rehype-sanitize, before showing Markdown written by other people.
Can I use Markdown in an email?
Convert it to an HTML fragment and paste it into your email tool's HTML or source view. Many email clients ignore style sheets, so keep formatting simple or use a tool that inlines styles.
How do I convert HTML back to Markdown?
Use an HTML to Markdown converter. The free one on aeromarkdown.app also accepts content copied from web pages and Google Docs.