Skip to content

How to Convert Markdown (README.md) to HTML

By Durim Hoti · Last updated

A README is written to be read on GitHub or GitLab. As a standalone web page it needs a little care: the page needs a <head>, links to headings need ids, and images and other files must be reachable from wherever the HTML ends up.

Convert a README step by step

  1. Open the Markdown to HTML converter.
  2. Click Open file and choose the README.md, or paste its text.
  3. Set Output to Full HTML document for a page that works on its own, or keep HTML fragment to paste into an existing page.
  4. Switch to Preview to check tables, lists and images.
  5. Click Download, and copy any images the README links to into the matching folders next to the downloaded file.

Example: a README with links, an image and a table

README.md
# weather-cli

Show the weather in your terminal.

- [Install](#install)
- [Usage](#usage)

## Install

```bash
npm install -g weather-cli
```

## Usage

![Screenshot](docs/screenshot.png)

| Option | Default |
| :----- | ------: |
| `--units` | metric |
HTML (fragment)
<h1 id="weather-cli">weather-cli</h1>
<p>Show the weather in your terminal.</p>
<ul>
<li><a href="#install">Install</a></li>
<li><a href="#usage">Usage</a></li>
</ul>
<h2 id="install">Install</h2>
<pre><code class="language-bash">npm install -g weather-cli
</code></pre>
<h2 id="usage">Usage</h2>
<p><img src="docs/screenshot.png" alt="Screenshot" loading="lazy"></p>
<table>
<thead>
<tr>
<th align="left">Option</th>
<th align="right">Default</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>--units</code></td>
<td align="right">metric</td>
</tr>
</tbody></table>

The headings got the ids install and usage, so the two links at the top work in the HTML. The image path docs/screenshot.png stayed exactly as written (with loading="lazy" added), the table kept its column alignment, and the code block kept its language as a language-bash class.

Table problems and what the GFM rules say

Most surprises in converted READMEs are tables. The converter follows the GitHub Flavored Markdown specification, so these results are expected, not bugs:

A pipe inside inline code splits the cell

In a table, every unescaped | starts a new cell, even inside backticks. In the first row below, the code turns into two cells with stray backticks, and the text "either value" is dropped as an extra cell. Write \| instead:

Markdown
| Flag | Meaning |
| --- | --- |
| `a|b` | either value |
| `a\|b` | either value |
HTML
<table>
<thead>
<tr>
<th>Flag</th>
<th>Meaning</th>
</tr>
</thead>
<tbody><tr>
<td>`a</td>
<td>b`</td>
</tr>
<tr>
<td><code>a|b</code></td>
<td>either value</td>
</tr>
</tbody></table>
The Markdown to HTML converter in Preview mode: a table where the first row is split into the cells `a and b` because of an unescaped pipe, and the second row correctly shows a|b as code next to either value.
Unescaped, the pipe splits the first row; escaped as \| the second row is correct.

A row with an extra cell loses it

Cells beyond the header's column count are dropped without a warning:

Markdown
| Name | Size |
| --- | --- |
| logo.png | 12 KB | old |
HTML
<table>
<thead>
<tr>
<th>Name</th>
<th>Size</th>
</tr>
</thead>
<tbody><tr>
<td>logo.png</td>
<td>12 KB</td>
</tr>
</tbody></table>

A short delimiter row means no table at all

The | --- | row must have as many cells as the header row. Otherwise the whole block stays a paragraph:

Markdown
| Name | Size | Type |
| --- | --- |
| logo.png | 12 KB | image |
HTML
<p>| Name | Size | Type |
| --- | --- |
| logo.png | 12 KB | image |</p>

A row with too few cells, on the other hand, gets empty cells added. The rules are in section 4.10 of the GFM specification.

HTML inside the README

READMEs often contain bits of HTML. With the default setting Allow safe tags, formatting tags stay and scripts are removed:

Markdown
Click <b>Run</b>.

<script>alert('hi')</script>
HTML
<p>Click <b>Run</b>.</p>

The <b> tag stayed, and the script was removed completely, including its content. Choose Show as text to display all HTML tags literally, or Keep as written only for files you trust.

What to do next

To write and preview Markdown with a live result, use the Markdown editor. To try the generated page with your own CSS, paste it into the online HTML editor; our guide on running HTML online shows how. Coming from Word instead? See how to convert Word to HTML.

FAQ

Does the converter support GitHub Flavored Markdown?
Yes, it is on by default: tables with column alignment, task lists, strikethrough and bare URLs. Its table output matched all eight table examples of the GFM specification (version 0.29-gfm) in our test.
Will links to headings like #install work in the HTML?
Yes. Headings get GitHub-style ids, so ## Install becomes id="install" and a link to #install jumps to it. A second heading with the same text gets install-1.
Is the result the same as on github.com?
The Markdown rules are the same GFM rules, and the table rules matched the specification in our test. We haven't compared the output with github.com itself, which adds its own styles and features on top.
Is HTML inside the Markdown kept?
By default, safe tags such as <b> are kept and anything that could run code, such as <script>, is removed. You can also show raw HTML as text, or keep it exactly as written if you trust the file.
Is my README uploaded?
No. The conversion runs in your browser. Only images the Markdown links to are loaded from their websites when the preview shows them.

Try it and keep reading