DEV Community

Anup Karanjkar
Anup Karanjkar

Posted on Originally published at wowhow.cloud

Markdown Cheat Sheet: CommonMark and GFM Syntax

This Markdown cheat sheet lists the syntax that converts plain text to HTML: # for headings, * or _ for emphasis, - for lists, backticks for code, and [text](url) for links. CommonMark is the baseline specification, currently version 0.31.2, dated 2024-01-28.[1] GitHub Flavored Markdown (GFM) builds on it and adds tables, task lists, strikethrough and extended autolinks.[2] Below: a bookmarkable reference table, the exact spec output for each pattern, GFM-only features, and the mistakes that break rendering. To try any snippet, paste it into the free Markdown editor.

The cheat sheet at a glance

Every row below comes from the CommonMark spec, the GFM spec or GitHub's formatting docs. The last column says which one, so you know whether a pattern works everywhere or only on GFM renderers.

Element Syntax Source

| Heading | # foo through ###### foo | CommonMark, Example 62 |

| Italic | *text* or _text_ | GitHub Docs |

| Bold | **text** or __text__ | GitHub Docs |

| Strikethrough | ~~text~~ or ~text~ | GFM, Example 491 |

| Block quote | > text | GitHub Docs |

| Inline code | code | GitHub Docs |

| Fenced code block | Three backticks or three tildes, plus an optional language | CommonMark, Examples 142, 143 |

| Link | [text](/uri "title") | CommonMark, Example 482 |

| Image | ![alt](/url "title") | CommonMark, Example 572 |

| Bullet list | -, * or + before each item | GitHub Docs |

| Numbered list | 1. before each item | GitHub Docs |

| Task list | - [ ] todo and - [x] done | GFM, Example 279 |

| Horizontal rule | ***, --- or ___ | CommonMark, Example 43 |

| Hard line break | Two or more trailing spaces, or a trailing backslash | CommonMark, Example 633 |

| Escape a character | \* before the Markdown character | CommonMark, Example 12; GitHub Docs |

| Footnote | [^1] and [^1]: text | GitHub Docs |

| Hidden comment | <!-- text --> | GitHub Docs |

One caution on the "Source" column. GitHub Docs describe how github.com renders Markdown. They are not a spec for every renderer, so footnotes and alerts below are GitHub behavior, not CommonMark.[3]

Headings and paragraphs

A heading is one to six # characters followed by text. The number of hashes sets the level.[3] The spec's Example 62 maps # foo to <h1>foo</h1>, and so on down to <h6>.[1]

Two edge cases catch people. Seven hashes is not a heading: Example 63, ####### foo, renders as the paragraph <p>####### foo</p>.[1] And a hash with no space after it is not a heading either. Example 64 shows #5 bolt and #hashtag both coming out as plain paragraphs.[1] That second rule matters on any platform where you paste a line starting with a hashtag.

Emphasis: bold, italic and strikethrough

GitHub's docs give two spellings for each: italic is *text* or _text_, and bold is **text** or __text__.[3] They are not fully interchangeable, though. In CommonMark, foo*bar* renders as foo<em>bar</em> (Example 355), while foo_bar_ stays literal text, <p>foo_bar_</p> (Example 360).[1] Underscores do not start emphasis in the middle of a word. If you need italics inside a word, use asterisks. It also means snake_case_names are safe from accidental italics.

Strikethrough is a GFM addition. The spec defines it as text wrapped in a matching pair of one or two tildes.[2] Example 491 takes ~~Hi~~ Hello, ~there~ world! to <del>Hi</del> Hello, <del>there</del> world! inside a paragraph.[2] A renderer that implements only core CommonMark will show the tildes as literal characters.

Lists, nesting and task lists

Bullet lists start each item with -, * or +. Numbered lists start with a number and a period. A nested list is indented under its parent item.[3] GitHub's own nested example indents each level three spaces:[3]

1. First list item
   - First nested list item
     - Second nested list item
Enter fullscreen mode Exit fullscreen mode

Two list rules produce surprises. First, the bullet character is part of the list's identity: Example 301, - foo, - bar, + baz, renders as two separate <ul> lists, one holding foo and bar and another holding baz.[1] Pick one marker per list and keep it. Second, the first number in an ordered list is meaningful. Example 267, 0. ok, renders as <ol start="0">.[1]

Task lists are a GFM extension. A task list item is a list item whose first paragraph begins with [ ] for unchecked or [x] for checked, followed by whitespace. The spec says the character between the brackets can be a space or an x, in lowercase or uppercase.[2] Example 279 renders - [ ] foo and - [x] bar as list items containing a checkbox <input>, with the second one marked checked="".[2]

The spec also notes that it does not define how the checkboxes are interacted with, so whether a rendered box is clickable depends on the renderer.[2] GitHub's docs add one gotcha: if a task item's description begins with a parenthesis, escape it, as in - [ ] \(Optional) Open a followup issue.[3]

Code: inline spans and fenced blocks

Single backticks mark code inside a sentence, and the text inside is not formatted.[3] For a block, GitHub's docs say to use triple backticks.[3] The CommonMark spec also allows tildes as the fence, and the text after the opening fence is the info string. Examples 142 and 143 both turn an info string beginning with ruby into <pre><code class="language-ruby">.[1]

Enter fullscreen mode Exit fullscreen mode


ruby
def foo(x)
return 3
end

Enter fullscreen mode Exit fullscreen mode


markdown

The spec only defines the class name in the output. None of the three sources opened for this guide covers a literal triple backtick inside a fence, so this guide leaves it out. Check your renderer's docs for that case.

Links, images and autolinks

A link is link text in square brackets followed by the destination in parentheses. GitHub's example is [GitHub Pages](https://pages.github.com/).[3] An optional quoted title follows the URL: Example 482, [link](/uri "title"), renders as <a href="/uri" title="title">link</a>.[1] An image is the same syntax with a leading !, and the bracketed text becomes the alt text.[3] Example 572 renders ![foo](/url "title") as <img src="/url" alt="foo" title="title" />.[1] Write real alt text, since GitHub describes it as a short text equivalent of the information in the image.[3]

GFM adds autolinks that need no angle brackets. Three kinds are defined, and each is recognized only at the start of a line, after whitespace, or after one of the characters *, _, ~ and (.[2]

www.commonmark.org
http://commonmark.org
foo@bar.baz
Enter fullscreen mode Exit fullscreen mode


plaintext

Per the spec, the first becomes a link to http://www.commonmark.org because the scheme http is inserted automatically (Example 622). The second is an extended URL autolink for http:// or https:// followed by a valid domain (Example 629). The third becomes a mailto: link, with the scheme added automatically (Example 630).[2]

Trailing punctuation is handled for you. The characters ?, !, ., ,, :, *, _ and ~ at the end are not part of the link, though they may appear inside it. So Visit www.commonmark.org. links the domain and leaves the period outside (Example 624).[2] Unmatched closing parentheses are also left out: www.google.com/search?q=Markup+(business))) links through the first closing parenthesis and leaves the other two outside the link (Example 625).[2]

Line breaks, rules and escapes

A hard line break is a line ending preceded by two or more spaces, rendered as <br /> (Example 633).[1] The spec also provides a backslash form, so a backslash at the end of the line gives the same <br /> without invisible trailing spaces.[1] Prefer the backslash. Trailing spaces are easy to lose in an editor that trims whitespace on save.

A horizontal rule is three of *, - or _ on a line. Example 43 renders ***, --- and ___ each as <hr />.[1]

To show a Markdown character literally, put a backslash before it. GitHub's example is Let's rename \*our-new-project\* to \*our-old-project\*., which stops the asterisks from creating emphasis.[3] Example 12 in the spec escapes the full run of ASCII punctuation characters, and the HTML output shows each one as plain text with the backslash gone.[1]

Tables: one line here, a full guide elsewhere

GFM enables a table extension, which adds one more leaf block type.[2] Tables are an extension, not part of core CommonMark, so a renderer without that extension may not turn pipe-delimited source into a table. Alignment colons, pipe escaping and the failure cases fill a full guide of their own: see the Markdown table syntax guide.

GitHub-specific extras

These three are documented by GitHub, not by the CommonMark spec, so treat them as GitHub behavior unless your renderer says otherwise.[3]

Here is a simple footnote[^1].

> [!NOTE]
> Useful information that users should know, even when skimming content.
Enter fullscreen mode Exit fullscreen mode

Footnotes use a [^1] reference and a [^1]: definition. An HTML comment hides content from the rendered output. Alerts are a special blockquote line naming the type, followed by the alert text in a standard blockquote. GitHub lists five types: NOTE, TIP, IMPORTANT, WARNING and CAUTION.[3]

Raw HTML and the tag filter

GFM also enables a tagfilter extension. When it is on, these nine HTML tags are filtered in the rendered output: <title>, <textarea>, <style>, <xmp>, <iframe>, <noembed>, <noframes>, <script> and <plaintext>.[2] In Example 657 the filtered tags come out as escaped text, <title>, while a <strong> and an <em> in the same line pass through untouched.[2] So with the tagfilter on, an iframe or script tag pasted into a GFM document comes out as escaped text. Do not rely on raw HTML for layout in a document that may be rendered by a GFM-compatible tool.

Common mistakes and what causes them

Symptom Cause Fix Source

| Heading shows as plain text with hashes | No space after #, or seven or more hashes | Use one to six hashes and a space | Examples 63, 64 |

| Italics missing inside a word | Underscores do not open emphasis mid-word | Use asterisks | Examples 355, 360 |

| One list splits into two | The bullet character changed partway | Keep one marker per list | Example 301 |

| Numbered list starts at 0 or another number | The first number sets the start value | Begin with the number you want shown first | Example 267 |

| Strikethrough shows tildes | The renderer has no GFM strikethrough | Check the renderer's flavor | GFM spec |

| Checkbox shows as [ ] text | The renderer has no task list extension | Check the renderer's flavor | GFM spec |

| Line break disappears | Trailing spaces trimmed by the editor | End the line with a backslash | Example 633 |

| Asterisks vanish and text turns italic | Unescaped Markdown character | Put a backslash before it | Example 12 |

Check which flavor your renderer runs

The biggest source of "Markdown that doesn't work" is flavor, not syntax. Tables, task lists, strikethrough and bare-URL autolinks are GFM extensions, so each depends on the renderer enabling them.[2] Footnotes and alerts, as documented here, are GitHub features.[3] Versions differ too: the CommonMark page opened for this guide is 0.31.2 (2024-01-28), while the GFM spec page is version 0.29-gfm (2019-04-06).[1][2] This guide does not map which rules changed between those two versions, so verify any edge case in the renderer you publish to.

The quickest check is to paste a mixed sample into the Markdown editor and read the preview. The editor's parser is not verified against the spec examples cited here (unconfirmed), so treat its preview as a drafting aid and confirm the final output where the document will live.

Quick reference

Headings take one to six hashes plus a space. Italics use one asterisk or underscore, bold uses two, and strikethrough uses one or two tildes on GFM. Lists use -, * or + and keep a single marker per list. Code uses single backticks inline and triple backticks or tildes for a block. A link is [text](url) and an image adds a leading !. Task lists are - [ ] and - [x]. A backslash escapes any Markdown character and a trailing backslash breaks a line. Core CommonMark is the safe baseline. Everything else depends on your renderer.

Sources

  1. CommonMark Spec, version 0.31.2, 2024-01-28 (accessed November 27, 2026)

  2. GitHub Flavored Markdown Spec, version 0.29-gfm, 2019-04-06 (accessed November 27, 2026)

3. Basic writing and formatting syntax, GitHub Docs (accessed November 27, 2026)

Originally published at wowhow.cloud

Top comments (0)