How to Convert Markdown to HTML (and Back)
Markdown is a lightweight markup language that converts to HTML. It's the standard for READMEs, documentation, blog content, and developer communication. Converting between Markdown and HTML is a common task โ writing in Markdown for simplicity, then converting to HTML for web publishing, or extracting Markdown from existing HTML content.
Quick Markdown Syntax Reference
Headings: # H1, ## H2, ### H3. Bold: **text**. Italic: *text*. Links: [text](url). Images: . Code: `inline` or ``` fenced blocks. Lists: - unordered or 1. ordered. Blockquotes: > text. Horizontal rules: ---. Tables use pipes and dashes to define columns and rows.
Converting Markdown to HTML
In JavaScript, marked and markdown-it are the standard libraries: marked.parse('# Hello') returns '<h1>Hello</h1>\n'. In Python, markdown and mistune handle conversion. GitHub Flavored Markdown (GFM) adds tables, task lists, and strikethrough โ most converters support this extension. The Markdown to HTML tool converts instantly in your browser โ paste Markdown on the left, see rendered HTML on the right.
Worked Example: How Closely Converters Follow the Spec
Markdown has a formal specification, CommonMark, with 652 numbered examples in version 0.31.2. We ran them all through marked 4.3.0 โ the library behind our Markdown tools โ and through the hand-written renderer our Markdown Preview used before October 2026: marked produced the expected HTML for 571 of 652 examples, the old renderer for 2 (same whitespace-normalized comparison; script in our test folder). Most of marked's misses are rare edge cases (deeply nested lists, unusual link syntax); everyday headings, emphasis, lists, links, code and tables match.
Two practical warnings. First, Markdown allows raw HTML, so converting untrusted Markdown can pass a <script> or an onerror attribute straight into your page โ sanitize the output (our Markdown Preview runs DOMPurify on it). Second, different libraries differ on extensions such as tables, task lists and footnotes; GitHub Flavored Markdown is the most common target, so test with the converter your site will actually use.
Converting HTML to Markdown
The reverse conversion โ HTML to Markdown โ is useful for extracting content from web pages for documentation or migration. The HTML to Markdown tool strips HTML tags and converts them to Markdown equivalents: <h1> becomes #, <strong> becomes **, and <a href="โฆ"> becomes [text](url). Complex HTML with nested divs and custom classes won't convert perfectly โ Markdown represents a subset of HTML's capabilities.
Markdown Best Practices
Use ATX-style headings (# H1) not Setext-style (underlines). Leave a blank line before and after headings, lists, and code blocks. Use fenced code blocks (```js โฆ ```) with language identifiers for syntax highlighting. Keep lines under 80-120 characters for readability in source form. Use reference-style links for long URLs to keep the source readable.