CommonMark Guide
CommonMark is a precise specification of Markdown: it says exactly how Markdown text must be turned into HTML, so different tools give the same result. This guide shows what that means with real examples.
New to Markdown? Start with Markdown Basics. Looking up syntax? Use the Markdown Reference.
What is CommonMark?
Markdown was created by John Gruber in 2004. His description was informal and left many cases open, such as how nested lists work or when _ makes text italic, so every parser filled the gaps its own way.
CommonMark started in 2014 as a community effort, including John MacFarlane (author of Pandoc) and Jeff Atwood (Discourse, Stack Overflow), to write those rules down. It has three parts:
- A written spec that defines each Markdown construct.
- Examples that act as tests. Each one pairs Markdown input with the exact HTML a parser must produce.
- Reference parsers, such as
cmark(C) andcommonmark.js(JavaScript).
CommonMark is a community specification, not an ISO or IETF standard. The IANA registry of Markdown variants (RFC 7764) lists it as a registered variant.
The current version of the spec is 0.31.2, released in January 2024.
What changes in practice
For most simple text, CommonMark and old Markdown parsers agree. The differences show up in edge cases. These are the ones that bite most often.
| Markdown | CommonMark result | Why |
|---|---|---|
#Heading |
Plain paragraph, not a heading | A space after # is required. Some older parsers accept it. |
snake_case_word |
Literal text, no italics | _ inside a word does not create emphasis. snake*case*word does. |
- one, - two, then * three |
Two separate lists | Changing the bullet character starts a new list. |
1. Install followed by - Download indented 2 spaces |
- Download is not nested |
A child must be indented to the parent's content. For 1. that is 3 spaces. For - it is 2. |
foo\ at the end of a line, then bar |
A hard line break (<br />) |
A backslash is a line break marker. Two trailing spaces also work. |
A fenced block that opens with three backticks and js |
<pre><code class="language-js"> |
Fenced code blocks are part of CommonMark. They were not in the original Markdown. |
Try each one in the CommonMark dingus and compare with another parser.
What the spec covers
The spec has two layers.
Blocks (the structure of the document): paragraphs, headings (# style and underlined style), thematic breaks (---), indented and fenced code blocks, HTML blocks, link reference definitions, block quotes and lists.
Inlines (what happens inside a block): emphasis and strong emphasis, links, images, code spans, autolinks like <https://example.com>, raw HTML, and hard and soft line breaks.
It does not cover tables, task lists, strikethrough, footnotes, math or diagrams. Those come from extensions such as GFM.
CommonMark vs GitHub Flavored Markdown
GitHub Flavored Markdown (GFM) is defined as a strict superset of CommonMark. It adds five things:
| Feature | CommonMark | GFM spec |
|---|---|---|
| Tables | ||
Task list items (- [x]) |
||
Strikethrough (~~text~~) |
||
| Bare URL links | ||
Disallowed raw HTML (hides tags like script, iframe, style) |
GitHub.com also renders things the GFM spec does not define, such as footnotes, alerts, math and Mermaid. For the full support table, see the Markdown Reference. For the GFM details, see GitHub Flavored Markdown.
Who uses CommonMark, and how to check a tool
Tools and libraries built on CommonMark, or offering a CommonMark mode, include GitHub, GitLab, Discourse, Stack Overflow, Hugo (through Goldmark), Pandoc, markdown-it, commonmark.js, cmark and pulldown-cmark. Some tools do not follow it. Python-Markdown, for example, says it is not a CommonMark implementation and follows the original Markdown rules.
To check a tool yourself:
- Read its docs. Look for "CommonMark compliant" and which spec version it targets.
- Run the spec examples. The CommonMark repository ships the examples as a JSON file you can feed to any parser.
- Try the six cases above. If two or three differ, expect rendering surprises.
Many parsers have a CommonMark preset or mode. markdown-it, for example, has a commonmark preset: new MarkdownIt('commonmark').
Writing Markdown that behaves the same everywhere
- Put a space after
#in headings. - Use the same bullet character throughout one list.
- Use
*for emphasis inside a word, and_between words. - Indent nested lists by 4 spaces. That works in CommonMark and in older parsers.
- Add a blank line before and after block elements such as lists, code blocks and HTML.
- Do not rely on tables, task lists or footnotes unless you know the destination supports them. The reference page lists what each flavor supports: syntax by flavor.
More habits like these are in Markdown Best Practices and the Markdown Style Guide.
Frequently Asked Questions
- 1
Is CommonMark an official standard?
It is a community specification, not an ISO or IETF standard. It is widely used, and the IANA registry of Markdown variants lists it.
- 2
Why does the same nested list look different in two editors?
Parsers disagree on how far a child list must be indented. CommonMark ties it to the parent's content: 2 spaces under
-, 3 under1.. Some older parsers want 4. Using 4 spaces works in both. - 3
Does CommonMark change how I write Markdown?
Mostly not. Simple documents render the same. It matters for the edge cases in the table above and when you move content between tools.
- 4
What is the current version?
The current version of the spec is 0.31.2, released in January 2024. The spec is versioned and is not updated often.
- 5
Is every "Markdown" tool CommonMark compliant?
No. Some follow it fully, some partly, and some follow older rules. Check the tool's docs, or use the checks above.
