How Markdown maps to HTML
Markdown was created by John Gruber in 2004 as a way to write web content in plain text that still reads well before it is rendered. Every Markdown element corresponds to an HTML element: a line starting with # becomes h1, ## becomes h2, text wrapped in double asterisks becomes strong, single asterisks become em, and [text](url) becomes an a tag with an href.
The original description left many cases ambiguous, so different tools rendered the same text differently. CommonMark, a detailed specification with hundreds of test cases, was published to fix that, and GitHub Flavored Markdown (GFM) builds on it with tables, task lists and strikethrough. Most modern editors follow one of these two.
A worked conversion
Take this source, with a blank line between each block: '## Release notes', then 'Fixed **two** bugs and *one* typo.', then two list lines, '- Faster export' and '- See [docs](https://example.com/docs)'.
The converter produces an h2 for the heading, a p element containing a strong element around 'two' and an em element around 'one', and a ul containing two li elements, the second with a link to https://example.com/docs. The blank lines are not required: a paragraph line written directly under a heading is still wrapped in its own p tags, and consecutive lines of plain text are joined into one paragraph.
Where this converter differs from CommonMark
The converter is a small line-by-line parser that covers the everyday subset of Markdown: headings (# to ######), paragraphs, bold (**text** or __text__), italic (*text* or _text_), inline `code`, fenced code blocks (```), links, images, bulleted and numbered lists, block quotes and horizontal rules. It differs from CommonMark in a few predictable places:
- Tables, task lists, strikethrough, footnotes and reference-style links ([text][1]) are not converted and stay as plain text.
- Lists are one level deep. Indented sub-items become items of the same list rather than a nested list.
- Each line starting with > becomes its own blockquote element, so a multi-line quote produces several consecutive blockquotes.
- Asterisks and underscores only create emphasis when they hug the text, so '5 * 3 and 2 * 4' and snake_case_names are left alone, as in CommonMark.
- Single line breaks inside a paragraph are kept as plain newlines, which browsers display as a space, the same as in CommonMark.
Raw HTML and safety
Markdown allows raw HTML inside the source, but this converter deliberately does not pass it through. Every <, >, & and quote in your text is escaped, so a script tag or an onclick attribute typed into the source appears as visible text in the output instead of becoming live HTML. Links and images whose address starts with javascript:, vbscript: or data: are replaced with #.
The trade-off is that you cannot use raw HTML for things Markdown lacks, such as a figure caption or a details element; add those to the converted output by hand. If you later render Markdown from other people with a different library that does allow raw HTML, run its output through a sanitiser such as DOMPurify before inserting it into a page.
Getting the HTML ready for a CMS or email
Most CMS templates already output the page title as the only h1, so start Markdown headings at ## to keep a single h1 and a sensible heading order for screen readers and search engines.
Email is stricter than the web. Many email clients ignore style sheets, so formatting has to be added as inline style attributes, and links should use full absolute URLs. Paste the converted HTML into your email tool's code view and send a test message before using it in a campaign.
For links to other sites that open in a new tab, add target="_blank" together with rel="noopener" after converting, since Markdown link syntax has no way to express attributes.
Markdown to HTML Converter: frequently asked questions
Is Markdown a formal standard?
The original Markdown is an informal description, not a standard. CommonMark is the closest thing to one: a precise specification with a reference implementation, and GitHub Flavored Markdown is a documented superset of it used across GitHub.
Can I mix HTML into a Markdown document?
The Markdown format allows it: both the original Markdown and CommonMark accept inline and block HTML, which is how people add things Markdown has no syntax for, such as a figure caption. This converter escapes HTML instead, so tags in the source show up as text in the output. Add any extra HTML after converting.
Why do some Markdown files look different on GitHub and in my editor?
They are using different flavours. GitHub renders GFM, which adds tables, task lists, strikethrough and automatic links, while some editors use the original rules or their own extensions. Sticking to headings, emphasis, links and lists gives the most consistent results.
Should I store website content as Markdown or HTML?
Markdown is easier to write, review in version control and move between systems, so it suits documentation and blogs built from files. HTML is better when content needs precise layout, embedded media or attributes that Markdown cannot express.