HTML to Markdown
Published Updated
Paste HTML source and get Markdown as you type: headings, nested lists, pipe tables, code fences, links and images. Rich text copied from a page keeps its markup when pasted, unless the plain text already contains tags, as with code copied from an editor.
Rich text or source in
Rich text copied from a page keeps its markup: the paste handler reads the clipboard's HTML version when the plain-text copy contains no tags, and shows that markup in the box. If the plain text already holds tags (code copied from an editor, for example), the paste is left exactly as copied. You can also copy the markup from the source view or the browser's element inspector.
The conversion walks the parsed document and writes Markdown for the common elements. Anything else falls through to its text. Very deep nesting stops with a message: 500 nested div elements converted and 501 gave This HTML is too deeply nested to convert (more than 500 levels of nested tags) in Google Chrome 156, Chromium 153 (Playwright build, not Google Chrome), Firefox 155 and Playwright's WebKit build (not the Safari app). The same limit applied to nested span, b, blockquote and list tags. The browsers' own HTML parsers stop nesting at 510 or 511 levels and place deeper tags beside the last one, so a deeper paste gets the same message.
Element by element
Results from the page's own library in Chrome 156:
| HTML | Markdown written |
|---|---|
<h1> to <h6> | # to ######, with blank lines around |
<strong>, <b>, <em>, <i> | **bold**, *italic* |
<a href> | [text](<url>), text only when the URL is unsafe |
<img> |  |
<ul>, <ol> | - or 1. items, nested ones indented 4 spaces |
<pre><code class="language-js"> | A fence of at least three backticks, tagged js |
<code> | Inline backticks, longer when the code holds backticks |
<blockquote> | Each line prefixed with > |
<table> | A pipe table; the first row is the header |
<del>, <s>, <strike> | GFM strikethrough, text between two tildes |
<u>, <mark>, <sup> | Their text only, with no markup |
<dl>, <dt>, <dd> | Each term in bold on its own line with the definition below it; no definition-list syntax exists in CommonMark |
Table syntax is a GitHub Flavored Markdown extension, not part of base Markdown, so plain CommonMark renderers show the pipes as text.
Converted, then read back by a Markdown parser
We ran the site's own conversion code (lib/htmlToMarkdown.ts) in Chrome 156, Chromium 153, Firefox 155 and the WebKit build on 36 hand-written HTML snippets; the four engines wrote the same Markdown for every one. Each result was then turned back into HTML with marked 18.0.7, the Markdown parser this site's own Markdown to HTML tool uses, and its visible text compared with the original's. Some of the snippets:
| HTML | Markdown written | What marked made of it |
|---|---|---|
<p>Hello<b> world</b>, again</p> | Hello **world**, again | The same words, world in bold |
<p><em>Note: </em>read this</p> | *Note:* read this | Note: in italics, then read this |
<p>See<a href="https://example.com/docs"> the docs</a>.</p> | See [the docs](<https://example.com/docs>). | The same words with the link |
<div>First line</div><div>Second line</div> | Two paragraphs: First line, then Second line | Two paragraphs |
<p>1986. A good year for the harbour.</p> | 1986\. A good year for the harbour. | A paragraph that starts with 1986. |
<p>Shopping:<br>- milk<br>2. eggs</p> | Three lines; the dash and the 2. get a backslash | Three lines of text, no list |
<ol start="3"><li>Three</li><li>Four</li></ol> | 3. Three and 4. Four | A list numbered from 3 |
A table row with colspan="2" under a three-column header | That row with two cells | A third, empty cell added to the row |
| A table whose first row uses td, not th | The first row as the header row | The first row shown as a header |
<span style="font-weight:700">css bold</span> | css bold | Plain text: styling set with CSS is not read |
H<sub>2</sub>O, x<sup>2</sup> | H2O, x2 | H2O, x2 without lowering or raising |
An SVG data: image and a javascript: image | Their alt text only | Text; a PNG data: image was kept as an image |
A list of <input type="checkbox"> items | - done and - todo | A plain list; the checkboxes are dropped |
The table cell case follows the GitHub Flavored Markdown spec (version 0.29-gfm): when a row has fewer cells than the header row, "empty cells are inserted". The backslashes keep text as text: CommonMark 0.31.2 defines a bullet list marker as "a -, +, or * character" and an ordered one as digits followed by "a . character or a ) character", so an unescaped 1986. at the start of a line opens a numbered list. Not tested: HTML from word processors or email programs.
How long large pastes took
The Markdown box is rebuilt on every change. We set the HTML box of the real component to article-like markup (headings, paragraphs with bold, italic and links, short lists and small tables) of growing size and timed until the Markdown appeared, one run per size, in Chrome 156, Chromium 153, Firefox 155 and the WebKit build:
| Pasted HTML | Chrome 156 | Chromium 153 | Firefox 155 | WebKit build |
|---|---|---|---|---|
| 10 KB | 4 ms | 3 ms | 4 ms | 5 ms |
| 100 KB | 11 ms | 11 ms | 14 ms | 14 ms |
| 500 KB | 46 ms | 46 ms | 61 ms | 57 ms |
| 1 MB | 95 ms | 97 ms | 124 ms | 118 ms |
| 2 MB | 180 ms | 183 ms | 227 ms | 262 ms |
Every engine finished 2 MB within 0.3 seconds, and the time grew roughly in step with the size. Each table is converted from its own rows only, so a table inside a table cell is written once, inside that cell: 24 tables nested in one another converted in 3 ms or less in each engine. One run per size, on one Mac.
Converting markup
Step 1
Copy the HTML source
Either paste rich text copied from a page, which brings its markup along, or open View Source or the Elements panel and copy the markup itself.
Step 2
Paste it into the box
Markdown appears below at once, rebuilt on every keystroke. Empty input shows nothing.
Step 3
Copy Markdown
One button copies the whole result. Clear empties the box.
Where the result differs from what you may expect
- Line breaks: a
<br>inside a paragraph, list item or quote becomes a Markdown line break (two spaces and a new line), inside a table cell it stays a br tag, and inside a heading it becomes a space. - Special characters:
*,_,[,]and backslashes get a backslash;<and>become entities, and an&becomes an entity only where it would read as the start of one. - Link form: CommonMark allows
<url>destinations; some older converters expect bare ones. - The other way: to see Markdown as a page, use Markdown to HTML; for a document, Markdown to PDF.
HTML to Markdown questions
Does pasting text copied from a web page keep its formatting?
Yes. When the clipboard holds rich text and the plain copy contains no tags, the box receives the markup behind it, so headings, bold text, links and lists are converted. Text that already contains tags, such as code copied from an editor, is pasted exactly as copied.
Why are my link addresses wrapped in angle brackets?
CommonMark allows a link destination inside < and >, and inside them parentheses need no special care. A Wikipedia address ending in (planet) survives intact. Most renderers accept the form.
Why does the output show < and > as entities?
Text is escaped so markup in the original, such as a decoded <script>, cannot return as live tags when the Markdown is rendered elsewhere. A plain ampersand stays an ampersand; only one that would read as the start of an entity, such as &amp;, is escaped.
What is removed on purpose?
Script and style elements, comments, and links or images whose address starts with javascript: or vbscript:. A data: address is kept only for PNG, JPEG, GIF, WebP, BMP and icon images. The link text stays.
What happens to tables with merged cells?
Tables become pipe tables with the first row as the header. A cell spanning two columns becomes one cell, so its row has one cell fewer than the header; the GitHub Flavored Markdown spec says that for such a row "empty cells are inserted", and marked 18.0.7 added one in our test. Pipes in cell text are escaped.
Is the HTML I paste sent to a server?
The browser's own DOMParser reads the markup in this tab, and the conversion code makes no network request. In our test runs in four browsers, which logged every request, the only requests were for the test page and its script; none carried the pasted HTML.
Are the spaces next to bold, italic or linked words kept?
Yes. A space just inside the tag, as in Hello<b> world</b>, is written outside the asterisks: Hello **world**. The marked parser read back the same words for bold, italic, strikethrough and links. Two words with no space between them in the HTML, as in <b>bold</b>text, stay joined, as the browser shows them.
Why does a line that starts with a number or a dash get a backslash?
In Markdown a line starting with 1986. or - or # would turn into a list or a heading. The tool puts a backslash before that mark in paragraph text (1986\. A good year), which a Markdown reader shows as 1986. again. The marked parser kept all four such snippets as plain paragraphs. A #hashtag or -5 is left alone, because without a following space it is not a marker.
Is bold or italic set with CSS converted?
No. Only the tags count: b and strong, i and em, del, s and strike. A span with font-weight 700 and one with font-style italic came out as plain words. Underline, highlight, superscript and subscript also become plain text, so x<sup>2</sup> reads x2.
How large a paste can it handle?
2 MB of article-like HTML with many small tables converted in 0.18 seconds in Chrome 156 and Chromium 153, 0.23 in Firefox 155 and 0.26 in the WebKit build. The Markdown is rebuilt on every change, so each edit of a very large paste converts it again. Nesting is limited to 500 levels of tags.
What happens to a table inside a table?
A Markdown pipe table cannot hold another table, so the inner table is written as text inside the outer cell, with its pipes escaped. <table><tr><td>cell L1 <table><tr><td>cell deepest</td></tr></table></td></tr></table> gave the two lines | cell L1 \| cell deepest \| \| --- \| | and | --- |. Check such a table by eye before you use the Markdown.