Free online tool

Upload a file

Drop your file hereTap to choose a file

or click to browse, or paste from the clipboard

← Back to Blog

How to Convert Markdown to HTML: GFM, Full Pages and Safe Output

To convert Markdown to HTML, run it through a Markdown parser: # to ###### headings become <h1> to <h6> elements, **bold** becomes <strong>, lists become <ul> or <ol>, and each block of text separated by a blank line becomes a <p> paragraph. Paste or open a .md file in the Markdown to HTML Converter to convert GitHub Flavored Markdown in your browser, or run pandoc README.md -f gfm -o README.html on the command line.

Two decisions matter more than the converter: whether you need a fragment or a complete page, and whether you trust whoever wrote the Markdown.

How to convert Markdown to HTML with Zutilium

The converter runs in your browser, so your Markdown is never uploaded, and it accepts up to 2 MiB of UTF-8 text.

  1. Open the Markdown to HTML Converter and type or paste into the Markdown box, choose Open file, or drop a .md, .markdown or .txt file on the editor.
  2. Under Output, pick HTML fragment to paste into a CMS, template or email, or Complete HTML document for a file that opens on its own.
  3. Choose a Formatting style: Indented, 2 spaces (the default), Indented, 4 spaces, Indented, tabs or Compact, no line breaks.
  4. Under Raw HTML in the Markdown, leave Keep it as written for your own text. For Markdown someone else wrote, choose Escape it, show it as text, or keep raw HTML and tick Sanitize: remove scripts, event handlers and unsafe links under Options.
  5. Check the Options. Add heading IDs is on by default, while Line breaks become <br> and External links open in a new tab start off. A complete document also takes a Page title, a Language (lang) code and Include a simple stylesheet.
  6. Review the preview, then press Copy HTML or Download .html.

The HTML and preview update as you type, and nothing in the sandboxed preview can run. The draft stays in the tab until you close it; only your options are remembered.

What the HTML looks like: a worked example

This Markdown uses the GitHub Flavored features most documents need:

# Release notes

Version **2.4** fixes ~~two~~ three bugs. See https://example.com/changelog for details.

## Checklist

- [x] Update the docs
- [ ] Tag the release

| Platform | Status |
| :------- | -----: |
| Windows | Ready |
| macOS | Testing |

```python
print("done")
```

With default settings, the converter returns this fragment:

<h1 id="release-notes">Release notes</h1>
<p>Version <strong>2.4</strong> fixes <del>two</del> three bugs. See <a href="https://example.com/changelog">https://example.com/changelog</a> for details.</p>
<h2 id="checklist">Checklist</h2>
<ul>
  <li><input checked="" disabled="" type="checkbox"> Update the docs</li>
  <li><input disabled="" type="checkbox"> Tag the release</li>
</ul>
<table>
  <thead>
    <tr>
      <th align="left">Platform</th>
      <th align="right">Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td align="left">Windows</td>
      <td align="right">Ready</td>
    </tr>
    <tr>
      <td align="left">macOS</td>
      <td align="right">Testing</td>
    </tr>
  </tbody>
</table>
<pre><code class="language-python">print(&quot;done&quot;)
</code></pre>

Other converters turn the same file into different HTML, which matters when your stylesheet or scripts expect particular markup. In a test with pandoc 3.9 and -f gfm, alignment came out as style="text-align: left;", each task item was wrapped in a <label>, and the code block got pandoc's own highlighting markup instead of a language-python class. Python-Markdown 3.8, which follows the original Markdown rules, left ~~two~~, both task boxes and the bare URL as plain text, even with its tables and fenced-code extensions on.

What GitHub Flavored Markdown becomes in HTML

GitHub Flavored Markdown (GFM) is CommonMark plus five extensions defined in the GFM spec: tables, task list items, strikethrough, extended autolinks and a filter for a few raw HTML tags. This is how the converter writes each one:

Markdown HTML from the converter Note
~~old~~ <del>old</del> One or two tildes
- [x] Done <input checked="" disabled="" type="checkbox"> Done Disabled, as in the spec
Colons in the delimiter row align="left", "center" or "right" On every cell in the column
www.example.com <a href="http://www.example.com"> Also https:// URLs and email addresses
A code fence tagged python <code class="language-python"> Read by Prism and highlight.js
## Getting Started <h2 id="getting-started"> GitHub's rule, not the spec

Heading IDs follow GitHub's documented rules for section links: letters are lowercased, spaces become hyphens, other punctuation is dropped, and a repeated heading gets -1, -2 and so on. Some results surprise people:

Heading ID
## What's new in v2.0? whats-new-in-v20
## Café & Crème café--crème
## FAQ, then ## FAQ again faq, then faq-1

Link to a heading by its ID, as in [Install](#install), and copy the ID from the output instead of guessing. Turn off Add heading IDs if your CMS adds its own.

Some github.com behavior is outside GFM, and the converter does not copy it:

  • Footnotes ([^1]), alerts such as > [!NOTE], emoji shortcodes like :smile:, math and Mermaid diagrams stay as plain text or code. Pandoc's gfm reader converts the first three if you need them.
  • The spec's disallowed raw HTML rule, which turns <script>, <iframe>, <style> and six other tags into text, is not applied. Raw HTML is kept as written, as CommonMark specifies, until you escape or sanitize it.
  • GitHub sanitizes the HTML it renders, removing script tags, inline styles and class or id attributes, so a README full of raw HTML can look different on GitHub than in any converter.

HTML fragment or complete HTML document

A fragment holds only the elements for your content, ready to drop into a page that already has a head, a character set and styles. A complete document wraps the same body in everything a browser needs to open it as a file.

Where the HTML goes Choose
CMS editor, blog post or site template HTML fragment
Email platform's HTML block HTML fragment
A file to share, attach or host by itself Complete HTML document
A Hugo, Jekyll or Eleventy site Neither: they convert Markdown when they build

Here is the complete document for a two-line file, with the stylesheet turned off:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Release notes</title>
  </head>
  <body>
    <h1 id="release-notes">Release notes</h1>
    <p>Version <strong>2.4</strong> is out.</p>
  </body>
</html>

The <title> comes from the Page title field, else the first # heading, else the file name. Include a simple stylesheet (on by default) adds a <style> block with a readable width, table borders and code backgrounds that follow the reader's light or dark setting.

Do not paste a complete document into a CMS. Its doctype, <html>, <head> and <body> tags do not belong inside a page, and a <style> block applies to the whole page, so the stylesheet's body and heading rules would restyle your site, not only the post.

Where the HTML ends up matters too:

  • Blogs: in WordPress, type /html for a Custom HTML block and paste the fragment. For users without the unfiltered_html capability, such as Contributors, WordPress strips tags like <script> and <iframe> on save, according to its Custom HTML block documentation.
  • Email: Gmail reads <style> blocks only from the head and caps them at 16,384 characters in total, according to Google's Gmail CSS reference. A fragment carries no styles, so your email template sets the look; send yourself a test first.
  • Docs: heading IDs give a help center or wiki page a linkable table of contents, and a complete document makes a single-file page to attach or host.

Need a file rather than a web page? Markdown to PDF makes a printable PDF, covered in how to convert Markdown to PDF, and Markdown to Word makes an editable DOCX, shown in the Markdown to Word example.

How to sanitize untrusted Markdown

Markdown is not a security boundary. CommonMark passes raw HTML through without escaping it, and a plain Markdown link can carry a javascript: address with no HTML at all. Take this input:

Hello <b onclick="steal()">there</b>.

<img src="cat.png" onerror="steal()">

[Win a prize](javascript:steal())

With Keep it as written, all three survive:

<p>Hello <b onclick="steal()">there</b>.</p>
<img src="cat.png" onerror="steal()">
<p><a href="javascript:steal()">Win a prize</a></p>

Escape it, show it as text turns the first two into visible text. The last line is Markdown, not HTML, so escaping leaves it alone, but Escape also removes any link or image address a browser could run, and the link keeps only its text:

<p>Hello &lt;b onclick=&quot;steal()&quot;&gt;there&lt;/b&gt;.</p>
<p>&lt;img src=&quot;cat.png&quot; onerror=&quot;steal()&quot;&gt;</p>
<p><a>Win a prize</a></p>

Escape keeps link addresses that are relative or use http, https, mailto or tel, and image addresses that are relative, use http or https, or embed a PNG, GIF, JPEG, WebP or AVIF picture as a data: URL. Every other address goes, including disguised ones such as &#106;avascript: and java&Tab;script:, which a browser still reads as javascript:. The check is stricter than a browser's because it ignores encoded spaces and control characters, so a harmless relative link such as a&#32;b:c loses its address too. For this input the line under the HTML ends with "Removed 1 unsafe URL."

To render the safe parts of raw HTML instead of showing them as text, keep it and tick Sanitize. It keeps only an allowlist of formatting elements and attributes: event handlers and style attributes go, scripts, styles, iframes and SVG disappear with their contents, and links or images that use javascript:, data: or any scheme other than http and https (plus mailto and tel for links) lose their address. The same input becomes:

<p>Hello <b>there</b>.</p>
<img src="cat.png">
<p><a>Win a prize</a></p>

The status line under the HTML then ends with "Sanitized: removed 2 attributes and 1 unsafe URL." Tables, task lists and remote image addresses survive, and unlike GitHub's sanitizer it keeps id and class attributes, so heading IDs and code classes stay.

Use this to check a document before publishing. If your site accepts Markdown from visitors, sanitize in your own code on every render:

  • Convert first, then run the HTML through a maintained allowlist sanitizer. The OWASP XSS prevention cheat sheet recommends DOMPurify, and Marked's documentation says Marked does not sanitize its output.
  • Do not modify the HTML after sanitizing it; OWASP warns that this can undo the protection.
  • Know your converter's defaults. The pandoc manual warns that pandoc's HTML is not guaranteed to be safe, while cmark-gfm removes raw HTML and dangerous links unless you pass --unsafe.
  • Add a Content Security Policy as a second layer.

Markdown to HTML converters for the command line

For many files or a build step, use a command-line converter. They differ in GFM support and in how they handle raw HTML:

Converter GitHub Flavored Markdown Raw HTML and javascript: links
pandoc With -f gfm Passed through
marked (Node.js) On by default Passed through
cmark-gfm With -e extensions Removed unless --unsafe
Python-Markdown No: tables and fenced code via -x extra Passed through
# pandoc: GFM in, an HTML fragment out, one line per paragraph
pandoc README.md -f gfm --wrap=none -o README.html

# pandoc: a complete page whose <title> is set without adding a heading
pandoc README.md -f gfm -s --metadata pagetitle="Release notes" -o README.html

# marked (install with: npm install -g marked)
marked -i README.md -o README.html

# cmark-gfm with all five GFM extensions
cmark-gfm -e table -e strikethrough -e autolink -e tagfilter -e tasklist README.md > README.html

# Python-Markdown (install with: pip install markdown); toc adds heading IDs
python -m markdown -x extra -x toc README.md > README.html

Three pandoc details trip people up. Without -f gfm, pandoc reads its own Markdown dialect, which left the example's bare URL as plain text. It wraps output lines at 72 characters unless you add --wrap=none. And --metadata title= adds a second, visible title above your own # heading, while pagetitle sets only the <title>; with neither, pandoc 3.9 used the file name.

Troubleshooting

Line breaks disappear

A single line break inside a paragraph is a soft break, which browsers display as a space. End the line with two spaces or a backslash to get a <br>, leave a blank line to start a new paragraph, or tick Line breaks become <br> to keep every break, the way GitHub shows issues and comments.

A table shows up as lines of pipes

The header row needs a delimiter row of hyphens under it, with the same number of cells. If the counts differ, the GFM spec says it is not a table. To put a pipe inside a cell, escape it as \|.

Code blocks have no colors

The converter tags each fenced block with a class such as language-python but adds no colors. Load a highlighter on the page; Prism and highlight.js both read language-* classes.

Images are missing from the preview

The preview fetches nothing from other sites unless you tick Load remote images in the preview, and relative paths such as images/logo.png point nowhere inside it. The HTML keeps relative and http or https image addresses as written, so the images load once the page sits next to them.

Accented letters turn into é and similar

That is UTF-8 text read in the wrong encoding. A complete document declares <meta charset="utf-8"> in its first lines, and MDN notes that the declaration must fall within the first 1024 bytes. A fragment relies on the page it is pasted into to declare UTF-8.

Frequently asked questions

How do I convert an MD file to HTML?

Open the file in the Markdown to HTML Converter, choose Complete HTML document and press Download .html; README.md downloads as README.html. On the command line, pandoc README.md -f gfm -s -o README.html does the same job. Both read GitHub Flavored Markdown, so tables and task lists convert.

Is GitHub Flavored Markdown the same as CommonMark?

No. GFM is a strict superset of CommonMark that adds tables, task lists, strikethrough, extended autolinks and a filter for some raw HTML tags. A CommonMark-only parser leaves GFM tables as lines of pipes and task boxes as [x] text.

Does converting Markdown to HTML remove scripts?

Usually not. Markdown allows raw HTML, so most converters copy a <script> tag or an onerror attribute into the output, and links can point to javascript: addresses. Zutilium's converter does too with the default Keep it as written, so for anything you did not write, choose Escape it, show it as text or select Sanitize. Its preview never runs scripts, but the HTML you copy or download can.

How do I add CSS to Markdown converted to HTML?

Choose Complete HTML document with Include a simple stylesheet for a readable page that follows light and dark mode, or link your own stylesheet in the head. A fragment takes on the styles of the page it is pasted into. Sanitize removes style attributes, so use classes and a stylesheet rather than inline styles.

Can I convert HTML back to Markdown?

Yes, with pandoc: pandoc page.html -f html -t gfm -o page.md. Check lists afterwards: in a test with pandoc 3.9, GitHub-style task lists came back as plain lines without bullets or boxes. If your source is a PDF with selectable text, PDF to MD extracts it as Markdown; the PDF to Markdown guide covers scans and cleanup.