Converting Markdown to HTML: Syntax Mapping, How It Works, Safe Output
Markdown is a lightweight markup syntax for expressing document structure with easy-to-remember symbols and converting it into HTML. This article explains how syntax such as headings, lists, links, images, code, and tables maps to HTML tags, how conversion happens, uses in blogs and CMSs, and how to produce safe HTML output through sanitization.
Have you ever seen writing like "# Heading" or "- bullet" in a README or a blog draft? That is Markdown. Instead of writing HTML tags directly, you express document structure with a small set of easy-to-remember symbols, then convert it into HTML for display. This article explains, step by step, what converting Markdown to HTML actually means, how the syntax maps to tags, how the conversion works, and how to produce output safely.
What Markdown Is: A Bridge to HTML
Markdown is a lightweight markup language that expresses document structure by adding a minimum of symbols to plain text. Proposed by John Gruber and others in 2004, it is now used as a standard nearly everywhere, including GitHub, blogs, and documentation tools. Its main aim is for the syntax itself to be readable, so the meaning comes across even without conversion.
Web browsers, however, understand HTML. So to finally display Markdown text as a web page, you need a conversion step that turns Markdown into the corresponding HTML tags. For example, "# Title" becomes <h1>Title</h1>, and "**bold**" becomes <strong>bold</strong>. The writer works in readable Markdown while HTML is used for display; this division of roles is the essence of Markdown.
The easiest way to see how it converts is to paste Markdown into the Markdown to HTML Converter and compare the HTML it outputs. You can see with your own eyes which tag each symbol turns into.
Markdown Syntax and Its HTML Tags
Markdown has a limited number of syntax rules, most of which map one-to-one to basic HTML tags. Here are the representative correspondences.
| Element | Markdown syntax | Converted HTML |
|---|---|---|
| Heading | # Heading 1 / ## Heading 2 | <h1> / <h2> |
| Paragraph | Text separated by blank lines | <p>…</p> |
| Emphasis | **bold** / *italic* | <strong> / <em> |
| List | - item / 1. item | <ul><li> / <ol><li> |
| Link | [text](URL) | <a href="URL">text</a> |
| Image |  | <img src="image URL" alt="alt"> |
| Code | `code` / fenced by ``` | <code> / <pre><code> |
| Quote | > quoted text | <blockquote> |
Headings are leveled by the number of # at the start of a line, with # through ###### mapping to <h1> through <h6>. Paragraphs become <p> simply by separating with blank lines, and lists become bulleted or numbered lists with a leading - or 1..
Links and images use very similar notation; an image just adds a leading !. For code, you wrap inline text in backticks, or use a "code block" fenced by three backticks for multiple lines. Tables are an extended syntax using vertical bars | and hyphens to define columns and headers, and in many environments they convert to <table>. To try which tag each symbol becomes, typing in the Markdown Editor with a live preview makes the relationships intuitive.
How Conversion Works: Parser and Renderer
Converting Markdown to HTML happens internally in roughly two stages.
- Parsing: the converter reads the input Markdown line by line and recognizes document structure, such as "this is a heading," "this is a bullet list," and "this range is emphasized." The result is gathered into an intermediate representation such as an abstract syntax tree (AST) that represents the document structure as a tree.
- Rendering: the recognized structure is reassembled into the corresponding HTML tags. A heading becomes
<h2>, a list becomes<ul><li>, and so on, with tags generated according to the meaning of the structure.
Thanks to this two-step approach of "understand the structure first, then turn it into HTML," nested symbols (such as emphasis inside a list) are handled correctly. Note that Markdown has dialects (variations in syntax), and GitHub Flavored Markdown (GFM), which includes tables, checkboxes, and strikethrough, is widely used. It is worth knowing that the same Markdown can produce slightly different results depending on which specification or converter you use.
When you want to quickly check a converter's behavior, it is handy to enter the syntax into the Markdown to HTML Converter and inspect the tag structure of the generated HTML.
Using It in Blogs and CMSs
The mechanism of converting Markdown to HTML is broadly useful in real web work.
1. Writing blogs and articles
Many blog tools and static site generators convert Markdown drafts into HTML at publish time. Writers can express headings and lists with symbols alone, without thinking about tags, so they can focus on the writing itself. Because drafts are plain text, they pair well with version control (such as Git) and make diffs easy to follow.
2. CMSs, documentation, and chat
Various CMSs, documentation sites, and chat tools also commonly convert entered Markdown into HTML on the server or in the browser for display. Once you learn the common syntax, you can write the same way across multiple services. When polishing a draft locally, using a preview-equipped tool like the Markdown Editor makes it easier to check the result before publishing.
Safe HTML Output: The Idea of Sanitization
Often overlooked yet very important in Markdown conversion is safe HTML output. Because much of Markdown allows HTML tags to be written directly, converting and displaying user-entered Markdown as-is can let dangerous tags like <script> slip in, potentially leading to cross-site scripting (XSS).
The idea that prevents this is sanitization. You inspect the converted HTML and remove everything except tags and attributes you have allowed in advance. Concretely, measures like the following are taken.
- Allowlist approach: pass only safe tags such as
<p>and<a>, and remove event attributes like<script>andonclick. - Link inspection: check that
hrefdoes not contain dangerous schemes such asjavascript:. - Disabling untrusted HTML: configure the converter so that raw HTML in user input is not converted at all, but escaped and shown as text.
If you are only converting drafts you wrote yourself, there is no need to worry excessively, but when you display Markdown entered by third parties, it is an iron rule to always sanitize the conversion result. Even for conversions that run entirely in the browser, the same idea applies when you embed the output HTML into an actual page.
Common Pitfalls When Converting
Finally, here are points that often confuse people when converting Markdown. Knowing how it works lets you avoid most of them.
| Pitfall | Cause and fix |
|---|---|
| No line break | A simple newline is often ignored in Markdown. Insert a blank line to split paragraphs. |
| List breaks apart | Align the space after the symbol and the indentation width of nested items. |
| Table not shown | Tables are extended syntax. You need a GFM-compatible converter. |
| Symbols shown literally | To output a symbol as text, add a backslash before it to escape it. |
Most of these stem from differences in Markdown specifications or dialects. When it does not convert the way you expect, checking the output HTML in the Markdown to HTML Converter and seeing which syntax becomes which tag makes it easier to pin down the cause. If you want to see the result as you write, using the preview-equipped Markdown Editor alongside it is efficient.
Through its division of roles, writing in readable syntax and converting to HTML, Markdown combines ease of writing with flexible display. Once you grasp three things, the syntax-to-tag mapping, the two-step conversion, and sanitization for safe output, you can confidently use it for both blogs and documentation.
Please note that this article is intended to provide general information. Markdown specifications and the implementations of converters and sanitizers differ by environment, and security requirements vary by use case. When adopting it for real, make your decision after checking the latest official specifications and documentation, and professional sources where needed.
FAQ
What does converting Markdown to HTML mean?
Markdown is a lightweight syntax that expresses document structure with easy-to-remember symbols, such as "# Heading" or "- bullet." Because web browsers understand HTML, displaying Markdown as a web page requires converting each symbol into the corresponding HTML tag. For example, "# Title" is converted into <h1>Title</h1>.
What are the main Markdown syntax and HTML correspondences?
Headings map to h1 through h6 by the number of #, paragraphs to p by blank-line separation, **bold** to strong, *italic* to em, - or 1. lists to ul/ol, [text](URL) to a,  to img, and backticks to code. Tables are an extended syntax using vertical bars and hyphens and convert to table in compatible converters.
My conversion result is not what I expected. Why?
Most often this is due to differences in Markdown specifications or dialects (such as GFM). Check that you split paragraphs with blank lines for line breaks, align the space after the symbol and indentation for lists, and use a GFM-compatible converter for tables. To output a symbol as text, escape it with a preceding backslash.
Is it safe to display the converted HTML on the web as-is?
For drafts you wrote yourself there is little risk, but be careful when displaying Markdown entered by third parties. Markdown often allows raw HTML, so script tags and the like slipping in can cause XSS (cross-site scripting). Always sanitize the output, keeping only allowed tags and attributes.
Is the content I enter in the WAZA TOOLS converter sent to a server?
WAZA TOOLS' Markdown to HTML Converter and Markdown Editor run entirely in your browser, so the content you enter is never sent to or stored on a server. They work on smartphones too, and you can convert Markdown to HTML as many times as you like, for free.