HTML to Markdown: Tables, Code Blocks and What Gets Lost

Last updated: · 7 min read

Moving a blog post into a static site generator, turning a help-centre article into a README, pasting something copied from a web page into a pull request description: in each case you hold HTML and need Markdown. The conversion is lossy by nature. Markdown can describe only a small set of structures, and it has no notion of colour, font size, class names or merged table cells. The HTML to Markdown Converter rewrites headings, emphasis, links, lists, code blocks and tables in CommonMark and GitHub Flavored Markdown (GFM) syntax and keeps just the text of anything that has no equivalent. This guide explains what each element becomes, which characters are escaped and why, and what to review before you publish the result. The output in the example is the tool's real result.

Formula

Rules:
1. The HTML is parsed leniently, the way browsers do it: unclosed <p>, <li> and <td> tags are repaired and character references such as &amp; are decoded.
2. h1–h6 become # headings; strong/b become **bold**, em/i *italic*, del/s ~~strikethrough~~; code, kbd and samp are wrapped in backticks (`).
3. A link becomes [text](url) and an image ![alt](src); a title attribute is appended in quotes. A link whose text equals its address is written as <https://…>.
4. ul lists use -, ol lists use 1. (starting from the start attribute if there is one); nested lists are indented. A checkbox at the start of an item becomes a [x] or [ ] task list item.
5. A pre block becomes a fenced code block with three backticks; if class="language-js" is present, the language goes on the opening fence. blockquote lines start with >, hr becomes ---, and a single br leaves two spaces at the end of the line.
6. The first row of a table is treated as the header and a GFM table is produced; an align attribute or a text-align style is carried into the delimiter row (:--, :-:, --:). colspan is filled with empty cells.
7. script, style, comments, form controls, iframe, svg, video and audio are dropped; tags with no Markdown equivalent, such as span, u and sup, keep only their text.
8. In plain text, the characters \ ` * [ ] ~, an _ at the edge of a word, and a leading #, >, -, + or "1." are escaped with a backslash.

Input:
<h2>Release 2.1</h2>
<p>Fixes the <code>parse()</code> bug &amp; adds <strong>dark mode</strong>. See the <a href="https://example.com/changelog">full list</a>.</p>
<ul>
  <li><input type="checkbox" checked> Update docs</li>
  <li><input type="checkbox"> Tag release</li>
</ul>
<pre><code class="language-js">const a = 1;
console.log(a);</code></pre>
<table>
  <tr><th>Plan</th><th align="right">Price</th></tr>
  <tr><td>Free</td><td>0</td></tr>
  <tr><td>Pro</td><td>9</td></tr>
</table>
<script>track();</script>

Output:
## Release 2.1

Fixes the `parse()` bug & adds **dark mode**. See the [full list](https://example.com/changelog).

- [x] Update docs
- [ ] Tag release

```js
const a = 1;
console.log(a);
```

| Plan | Price |
| ---- | ----: |
| Free |     0 |
| Pro  |     9 |

There is no formula here, only a set of mapping rules. The core syntax comes from the CommonMark specification; tables, task lists and strikethrough are not part of CommonMark but extensions defined by GitHub Flavored Markdown. The table and checkboxes in the output therefore render only where GFM is supported; a strict CommonMark renderer shows them as plain text. Columns are padded with spaces so the source stays readable; the padding has no effect on the rendered table.

What the inputs mean

HTML
The HTML to convert. It can be a whole page or a fragment; head, script and style sections are skipped automatically. Up to 1,000,000 characters and 256 levels of nesting are processed.

Worked example: Converting a release note to Markdown

  1. The input is the HTML fragment above. The <h2> heading is written with two # signs: ## Release 2.1.
  2. In the paragraph, the <code> element becomes `parse()`, the character reference &amp; is decoded and written as &, <strong> becomes **dark mode**, and the link becomes [full list](https://example.com/changelog).
  3. The two checkboxes in the list turn into a GFM task list: the item with the checked attribute is written as - [x] Update docs, the other as - [ ] Tag release.
  4. The <pre><code class="language-js"> block becomes a fenced code block opened by ```js; the line breaks inside it are kept exactly.
  5. The first table row is the header. The align="right" on the second column shows up in the delimiter row as ----:, and the numbers are right-aligned in the source as well.
  6. The trailing <script>track();</script> element does not appear in the output at all.

Result: The output consists of five blocks: a heading, a paragraph, a two-item task list, a code block tagged js and a three-row table whose Price column is right-aligned. Nothing of the script element remains.

📝 HTML to Markdown Converter

Free, no sign-up; your data stays in your browser.

Open the calculator →

How to read the result

Think of the conversion as one-way and lossy. Markdown has no colour, font, class, id, width or height; the text inside <span style="color:red"> survives, the colour does not. There is no syntax for underline (<u>), superscript (<sup>) or subscript (<sub>) either, so only the text is written: 10 m<sup>2</sup> becomes 10 m2. Tables cannot merge cells. colspan is compensated for with empty cells, whereas rowspan is ignored, which shifts the cells of the following row to the left. Tables like that need fixing by hand, or you can leave them as raw HTML, which Markdown permits. Preview the result in its destination before publishing, because different renderers display the same Markdown with small differences. This is general information.

Common mistakes

  • Assuming a table with rowspan carries over unchanged. A <td rowspan="2">x</td> cell is written in the first row only; the cell of the second row slides into the first column and the table reads wrongly.
  • Expecting a link that wraps a whole card to survive. <a href="/p"><h3>Title</h3><p>Text</p></a> comes out as ### Title and Text; a Markdown link cannot contain block elements, so the address is lost.
  • Using nested tables. A GFM table cell cannot hold block elements; the text of the inner table is written into the outer cell as plain text.
  • Deleting the escape characters because they look like errors. 2 * 3 [x] is written as 2 \* 3 \[x\]; the backslashes are not displayed, they only stop the asterisk from starting emphasis and the brackets from starting a link.
  • Thinking image dimensions are carried over. <img src="a.png" alt="Logo" width="40"> becomes ![Logo](a.png); width and height cannot be expressed in Markdown.
  • Hoping a table without a header stays that way. GFM requires a header row, so the tool turns the first row into the header even when it is made of <td> cells.
  • Pasting a fragment that contains nothing but script and style. The tool then reports "Nothing to convert: the input contains only skipped elements (script, style, comments)."

Frequently asked questions

Is the output CommonMark or GFM?

Both. Headings, emphasis, links, lists, blockquotes and code blocks are CommonMark syntax; tables, task lists and ~~strikethrough~~ are GFM extensions. If your destination does not support GFM, those three constructs appear as plain text.

How can I keep HTML that Markdown cannot express?

CommonMark allows raw HTML inside a Markdown document. To keep a table with merged cells or a tag such as <sup>, leave that part as HTML by hand; bear in mind that some platforms filter part of the raw HTML for security reasons. Apart from the <br> it writes for a line break inside a table cell, the tool does not emit raw HTML.

How are <br> line breaks written?

A single <br> is written as two spaces at the end of the line, which CommonMark treats as a hard line break. Two consecutive <br> elements start a new paragraph. If your editor strips trailing whitespace on save, these line breaks disappear.

Can I convert HTML copied from Word or Google Docs?

Headings, lists, links and tables carry over as long as they are written with tags. Editors of this kind tend to express formatting through inline styles, though, and the tool reads the style attribute only for table alignment (text-align), so bold or italic applied by a style is not converted.

Is my HTML uploaded to a server?

No, the conversion runs in your browser. It is still a good habit to strip pages that contain customer data before pasting them into any tool.

The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.

Sources

Choose your cookie preference to continue

Records the site needs to work (theme, language, favourites) stay in your browser.

This site is free and funded by ads.

With your consent, Google Analytics cookies measure visits and Google AdSense cookies are used to show ads; the data is processed on Google servers abroad.

If you reject, the site works just the same.

Cookie Policy · KVKK notice