How Markdown Converts to HTML: Rules and Example

Last updated: · 3 min read

Markdown lets you write bold text, headings and links with short plain-text marks, but a web page only displays HTML tags, so the marks must be converted. This guide explains the rules a Markdown converter follows to turn text into HTML source: headings, lists, tables, code blocks and links. It also shows why raw HTML typed into the text is escaped and why link schemes such as javascript: are blocked. Each step uses the real output of the converter in the example.

Formula

Block recognition, line by line (CommonMark 0.31.2):
# heading → <h1>heading</h1>  (the number of # signs, 1 to 6, sets the level)
Lines starting with - or * → <ul><li>…</li></ul>
| a | b | followed by |---|---| → <table> with thead and tbody
Lines between ``` fences → <pre><code class="language-lang">…</code></pre>
Other text separated by a blank line → <p>…</p>
Inline: **m** → <strong>m</strong>; *m* → <em>m</em>; `c` → <code>c</code>; [text](url) → <a href="url">text</a>
Before conversion, & < > are escaped to &amp; &lt; &gt;.

Block structures are recognised from the lines first (heading, list, code, table, paragraph), then inline marks are applied inside each block. Table syntax is not part of CommonMark; it follows the GitHub Flavored Markdown (GFM) specification. HTML tags typed in the text are escaped before conversion, so they appear as plain text and do not run. A link with a dangerous scheme such as javascript: is neutralised with href="#".

What the inputs mean

Markdown
The raw text to convert. Start headings with #, list items with - or *, and code blocks with three backticks. Windows line endings (CRLF) are normalised automatically.

Worked example: Heading, bold text, list and link

  1. Input: a line “# Hello”, a blank line, “**bold** and *italic* text.”, the list lines “- one” and “- two”, and “[site](https://example.com)”.
  2. “# Hello” has one # sign, so it becomes a level-1 heading: <h1>Hello</h1>.
  3. “**bold**” becomes <strong> and “*italic*” becomes <em>: <p><strong>bold</strong> and <em>italic</em> text.</p>.
  4. “- one” and “- two” are collected into one list block; in the output <li>one</li> and <li>two</li> sit on separate lines.
  5. The link [site](https://example.com) becomes <p><a href="https://example.com">site</a></p>.

Result: The output is four HTML blocks: a heading, a paragraph, a list and a paragraph with a link. In a browser it looks the same as the Markdown page would.

📝 Markdown to HTML Converter

Free, no sign-up; your data stays in your browser.

Open the calculator →

How to read the result

The output is a fragment, not a full HTML page: there is no doctype, head or body. Before placing the result on a page, check where the Markdown came from, and pass text written by users through an HTML sanitiser as well. Dialects differ in tables, task lists and footnotes; this tool follows GFM for tables and CommonMark for code blocks.

Common mistakes

  • Leaving no space after the # sign. In CommonMark, “#Hello” is not a heading; it stays an ordinary paragraph.
  • Writing nested lists without indentation. Sub-items usually need 2 to 4 spaces of indentation; an unindented line stays at the top level.
  • Expecting HTML tags in the text to work. A <script> tag typed in the input is escaped and appears as readable text.
  • Forgetting the closing fence. Without a final ``` line, all text below the code is shown as code.
  • Putting spaces inside a link address. In [text](my page) the link breaks; write %20 instead of the space or wrap the address in angle brackets.

Frequently asked questions

Why do I need to convert Markdown to HTML at all?

Browsers display HTML, not Markdown. The # and ** marks must be turned into heading and strong tags before the page can show a heading or bold text.

Why do tables not work in some converters?

Table syntax is not part of the CommonMark specification. It is defined by GitHub Flavored Markdown (GFM), so table support differs between tools.

Should I use ** or __ for bold?

Both produce bold text in CommonMark: **text** and __text__. A single asterisk or underscore produces italics: *text* and _text_.

Can I paste the output straight into my site?

Yes, if you wrote the text yourself or it comes from a trusted source. If visitors write the text, pass the output through an HTML sanitiser first.

The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.

Sources

Choose your cookie preference to continue

Records the site needs to work (theme, language, favourites) stay in your browser.

This site is free and funded by ads.

With your consent, Google Analytics cookies measure visits and Google AdSense cookies are used to show ads; the data is processed on Google servers abroad.

If you reject, the site works just the same.

Cookie Policy · KVKK notice