HTML isn't a text pattern — it's a tree, and regex doesn't know that
HTML is fundamentally nested structure: a `<strong>` inside an `<a>` inside a `<li>` inside a `<ul>`. A regular expression matches text patterns; it has no concept of nesting depth, no way to know that a closing `</div>` belongs to the third-nested `<div>` rather than the first. This is why regex-based HTML-to-Markdown converters — and there are many — tend to work fine on simple test cases and then quietly corrupt output the moment they meet real-world HTML: a link with a quote character in its title attribute, a nested list, an HTML comment containing what looks like a tag.
DOMParser sidesteps this entirely by using the browser's own HTML parsing engine — the same one that renders web pages — to build an actual tree structure first. Converting to Markdown then becomes a tree walk: visit each node, know exactly what it is and what it's nested inside, and emit the right Markdown syntax for that context. It's not a faster regex; it's a structurally different approach that can't make the class of mistakes regex parsing makes.
What survives the conversion, element by element
| HTML element | Markdown output |
|---|---|
| `<h1>`–`<h6>` | `#` through `######` headings |
| `<ul>` / `<ol>` / `<li>` | `-` bullets or numbered lists |
| `<a href>` | `text` |
| `<img src>` | `!alt` |
| `<code>` / `<pre>` | Inline backticks or fenced code blocks |
| `<blockquote>` | `>` quoted lines |
| `<table>` | GitHub-flavoured Markdown table with header separator row |
| `<strong>` / `<em>` | `bold` / `*italic*` |
| `<script>` / `<style>` | Dropped entirely |
Converting your HTML
Paste your HTML into the input box.
Click Convert to Markdown.
Review the Markdown output.
Copy the result.
Why scripts, styles, and inline formatting quietly disappear
Markdown has no equivalent for a `<script>` tag, a `<style>` block, or an inline `style="color:red"` attribute — Markdown describes document structure and basic emphasis, not executable code or CSS. This tool drops scripts and styles entirely and keeps only the text content of styled elements, discarding the styling itself. This isn't a bug or a gap in coverage; it's a consequence of what Markdown as a format is actually capable of representing. If you paste HTML that relies heavily on custom CSS classes for meaning (a colored warning box, a specifically styled callout), expect that visual distinction to be lost — only the underlying text and semantic tags (headings, lists, emphasis) survive.
Getting clean tables out of messy HTML
For straightforward tables — a header row plus simple data rows with no merged cells — the conversion to GitHub-flavoured Markdown syntax, complete with the required header-separator row, works cleanly and needs no manual cleanup afterward.
Common mistakes
Pasting HTML that depends on inline styles or CSS classes for meaning and expecting that visual distinction to carry over — Markdown has no mechanism for arbitrary styling.
Expecting merged table cells to convert cleanly — flatten or restructure the table first if the merge is meaningful to preserve.
Assuming JavaScript-driven content (elements populated dynamically after page load) will appear in the output — this tool converts the HTML you paste as-is, not whatever a script might later render into the page.
Pasting a full HTML document including `<head>` — the converter walks content tags, so unrelated head metadata won't produce meaningful Markdown output and is best trimmed first.
Real use cases
Converting a scraped or copied web article into clean Markdown for a static site generator or note-taking app.
Turning an HTML email template into Markdown for a documentation platform that only accepts Markdown source.
Migrating content from a CMS that exports HTML into a Markdown-based blog or wiki.
Cleaning up HTML copied from a rich-text editor into readable Markdown before committing it to version control.
Frequently asked questions
Q: Why DOMParser instead of regex?
A: Regex-based HTML parsing is brittle — it can't reliably handle nested tags, attributes with quotes, or malformed input. DOMParser gives the converter a real tree structure to walk instead of pattern-matching text.
Q: Are tables supported?
A: Yes — HTML tables are converted to GitHub-flavoured Markdown tables with the required header separator row.
Q: What about scripts and styles?
A: They're ignored entirely — only content tags are converted. Inline styles are dropped, and only the underlying text content survives.
Q: Is my HTML uploaded?
A: No. Conversion happens entirely in your browser.
Q: Will my HTML comments show up in the Markdown?
A: No — HTML comments aren't content nodes in the DOM tree the converter walks, so they're excluded from the output along with scripts and styles.
Q: My table had merged cells — why does the Markdown look wrong?
A: Standard Markdown tables assume a strict grid with no cell merging, so `colspan`/`rowspan` cells get flattened or duplicated across the columns they spanned — restructure the source table first if the merge is meaningful.
Convert your HTML now
Try it on the HTML to Markdown Converter. Want to preview the resulting Markdown rendered? Use Markdown Preview. Dealing with entity-encoded HTML first? Check HTML Entities Encode / Decode, or format the source HTML with the Code Formatter.