Skip to main content

← Back to blog

How to Convert Markdown to HTML (and Back Again)

Markdown lets you write formatted text with plain characters — # for a heading, - for a bullet, **bold** for emphasis. HTML is the tagged markup browsers actually render. Converting Markdown to HTML turns your shorthand into <h1>, <ul> and <strong>; going the other way turns messy HTML back into clean Markdown.

Exactly what our converter emits. Input ## Notes / See the [docs](/tools/) for **details**. / a two-item list, run through our Markdown to HTML converter, comes back as:

<h2>Notes</h2>
<p>See the <a href="/tools/">docs</a> for <strong>details</strong>.</p>
<ul>
<li>one</li>
<li>two</li>
</ul>

Notice what it does not add: no wrapper <div>, no classes, no <html> skeleton — just the block elements, which is what you want when pasting into a CMS that already has its own layout. The list items are not wrapped in <p> either, because the source list is tight rather than loose.

What Markdown becomes

MarkdownHTML
# Title<h1>Title</h1>
- item<ul><li>item</li></ul>
**bold**<strong>bold</strong>
[text](url)<a href="url">text</a>
```code```<pre><code>code</code></pre>

A converter walks your Markdown and emits the matching tags. Most tools follow GitHub-Flavored Markdown, which adds tables, task lists and fenced code blocks on top of the original spec.

Two constructs, straight out of our own Markdown ↔ HTML converter. A heading returns

<h1>Title</h1>

while a line of emphasis returns

<p><strong>bold</strong> and <em>italic</em></p>

The heading came back bare; the emphasis line came back wrapped in <p>. That is the rule behind most Markdown surprises: block-level constructs replace the paragraph, inline ones live inside it. Links are inline too, so [link](https://yunknow.cc/) produces

<p><a href="https://yunknow.cc/">link</a></p>

with the anchor nested in a paragraph rather than standing alone.

Markdown to HTML

This is the common direction: you wrote a README or a blog post in Markdown and need HTML to paste into a page, an email or a CMS. Paste the Markdown, convert, and copy the HTML. A preview helps you confirm the formatting looks right before you use it.

HTML to Markdown

The reverse is handy for cleaning up. Copy a section from a web page and it arrives as a tangle of <div>s and inline styles; converting to Markdown strips it down to the words and structure you actually want for notes or documentation. Note that HTML-only details — inline CSS, complex nested tables — can’t always be expressed in Markdown, so they get simplified.

Common Markdown pitfalls

A few habits cause most “why didn’t it render?” moments:

  • Lists need a blank line before them. Glue a list directly under a paragraph and many parsers treat it as one paragraph. Leave an empty line first.
  • A single line break is usually ignored. Markdown collapses one newline into a space. For a hard break, end the line with two spaces or leave a blank line to start a new paragraph.
  • Underscores inside words can trigger italics. In some flavors snake_case_name italicizes the middle chunk. Wrap it in backticks or escape the underscores: snake\_case\_name.
  • Indenting four spaces makes a code block. Accidental indentation silently turns text into <pre> output.

And here is the pitfall that generates the most surprised bug reports. This input has a single newline between two lines of text, and the converter returns

<p>line one
line two</p>

The newline survives inside the source but produces no <br> — both lines land in one <p>, and a browser renders them as one continuous line. A single newline is not a line break in Markdown; you need two trailing spaces, a backslash, or a blank line for a new paragraph. Lists, by contrast, do get real structure:

<ul>
<li>one</li>
<li>two</li>
</ul>

which is why “my line breaks disappeared” and “my list worked fine” are the same fact seen from two sides.

Frequently asked questions

Is Markdown standardized? The closest thing to a standard is CommonMark, with GitHub-Flavored Markdown adding tables, task lists and strikethrough on top. Flavors differ, so a footnote that works on one site may not on another.

Can I put HTML inside Markdown? Yes — most renderers pass raw HTML straight through, which is handy for the odd <sub> or <details> block that Markdown can’t express. Sanitizing renderers may strip it out.

Does the output include <html> and <body>? No. Converters emit an HTML fragment — just the <h1>, <p> and so on. Wrap it in a full document yourself if you need a standalone page. For a different markup language with far stricter rules, see our guide to XML.

Do it privately, in your browser

The Markdown ⇄ HTML converter runs entirely on your device — nothing is uploaded — and shows a sandboxed live preview that renders the layout without executing any scripts. Convert either direction, preview, then copy or download.

  • Keeping an eye on length while you write? Use the word counter.
  • Pasted text full of stray line breaks? Tidy it with the text cleaner.