Post

Ultimate Markdown Cheatsheet: Complete Syntax Guide with Examples

Master Markdown syntax with this comprehensive cheatsheet. Includes text formatting, code blocks, tables, links, images, and advanced features.

Ultimate Markdown Cheatsheet: Complete Syntax Guide with Examples

Markdown is the most popular lightweight markup language used by developers, writers, and content creators worldwide. Created by John Gruber, this ultimate markdown cheatsheet provides complete syntax examples for text formatting, code blocks, tables, links, images, and advanced features. Whether you’re writing documentation, README files, or blog posts, this comprehensive guide covers everything you need to master markdown syntax.

Table of Contents

Text Formatting

Emphasis

Bold text

1
**Bold text** or __Bold text__

Italic text

1
*Italic text* or _Italic text_

Bold and italic

1
***Bold and italic*** or **_Bold and italic_**

Strikethrough

1
~~Strikethrough~~

Superscript and Subscript

Einstein’s equation: E=mc2 (superscript)

1
E=mc<sup>2</sup>

Water molecule: H2O (subscript)

1
H<sub>2</sub>O

Escape Characters

Use backslash to escape special characters: *literal asterisks*

1
\*literal asterisks\*

Headers

H1 Header

H2 Header

H3 Header

H4 Header

H5 Header
H6 Header
1
2
3
4
5
6
# H1 Header
## H2 Header
### H3 Header
#### H4 Header
##### H5 Header
###### H6 Header

Setext Style (H1 and H2 only)

Header 1

Header 2

1
2
3
4
5
Header 1
========

Header 2
--------

Note: Setext style only supports H1 (=) and H2 (-) headers. Use ATX style for H3-H6.


Lists

Unordered Lists

  • Item 1
  • Item 2
    • Nested item
    • Another nested item
  • Item 3
1
2
3
4
5
* Item 1
* Item 2
  * Nested item
  * Another nested item
* Item 3

Ordered Lists

  1. First item
  2. Second item
    1. Nested item
    2. Another nested item
  3. Third item
1
2
3
4
5
1. First item
2. Second item
   1. Nested item
   2. Another nested item
3. Third item

Task Lists

  • Completed task
  • Incomplete task
  • Another completed task
1
2
3
- [x] Completed task
- [ ] Incomplete task
- [x] Another completed task

This is a Google link.

1
[Google](https://www.google.com "Google Homepage")

This is a reference link and another reference link.

1
2
3
4
5
[reference link][1]
[reference link][google]

[1]: https://www.google.com "Google"
[google]: https://www.google.com

https://www.google.com

1
https://www.google.com

Images

Inline Images

Markdown Logo

1
![Markdown Logo](https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/150px-Markdown-mark.svg.png "Markdown Logo")

Reference Images

HTML5 Logo

1
2
3
![HTML5 Logo][html5-logo]

[html5-logo]: https://www.w3.org/html/logo/badge/html5-badge-h-solo.png "HTML5 Logo"

Code

Inline Code

Use backticks for inline code.

1
Use `backticks` for inline code.

Code Blocks

1
Plain code block
1
2
3
```
Plain code block
```

Syntax Highlighting

1
2
3
function hello() {
    console.log("Hello World!");
}
1
2
3
4
5
```javascript
function hello() {
    console.log("Hello World!");
}
```

Indented Code Blocks

1
2
This is an indented code block
using 4 spaces or 1 tab
1
2
    This is an indented code block
    using 4 spaces or 1 tab

Line Numbers in Code Blocks

Note: Line numbers syntax varies by platform. Some use {linenos=true}, others use different attributes.

1
2
3
4
function hello() {
    console.log("Hello World!");
    return true;
}
1
2
3
4
5
6
```javascript {.line-numbers}
function hello() {
    console.log("Hello World!");
    return true;
}
```

Tables

Left AlignedCenter AlignedRight Aligned
LeftCenterRight
TextTextText
1
2
3
4
| Left Aligned | Center Aligned | Right Aligned |
|:-------------|:--------------:|--------------:|
| Left         | Center         | Right         |
| Text         | Text           | Text          |

Simple Table

Column 1Column 2Column 3
Data 1Data 2Data 3
Data 4Data 5Data 6
1
2
3
4
Column 1 | Column 2 | Column 3
---------|----------|----------
Data 1   | Data 2   | Data 3
Data 4   | Data 5   | Data 6

Blockquotes

This is a blockquote.

It can span multiple lines.

Nested blockquotes are also possible.

1
2
3
4
5
> This is a blockquote.
>
> It can span multiple lines.
>
> > Nested blockquotes are also possible.

Horizontal Rules

Three or more dashes, asterisks, or underscores:




1
2
3
---
***
___

Line Breaks

End a line with two or more spaces for a line break.

First line Second line

1
2
First line
Second line

HTML Elements

Definition Lists

Term 1
Definition 1
Term 2
Definition 2
1
2
3
4
5
6
<dl>
  <dt>Term 1</dt>
  <dd>Definition 1</dd>
  <dt>Term 2</dt>
  <dd>Definition 2</dd>
</dl>

Preformatted Text

Preformatted text
preserves   spaces
and line breaks
1
2
3
4
5
<pre>
Preformatted text
preserves   spaces
and line breaks
</pre>

Media

YouTube Videos (HTML)

Video Thumbnail

1
2
3
<a href="https://www.youtube.com/watch?v=mCG1tvUuCTo" target="_blank" rel="noopener">
  <img src="https://img.youtube.com/vi/mCG1tvUuCTo/0.jpg" alt="Video Thumbnail" width="240" height="180">
</a>

YouTube Videos (Markdown)

Video Thumbnail

1
[![Video Thumbnail](https://img.youtube.com/vi/mCG1tvUuCTo/0.jpg)](https://www.youtube.com/watch?v=mCG1tvUuCTo)

Special Features

Emoji

😄 ❤️ 👍 🐙 (Unicode) or :smile: :heart: :thumbsup: :octocat: (shortcodes)

1
2
😄 ❤️ 👍 🐙 (Unicode)
:smile: :heart: :thumbsup: :octocat: (shortcodes - requires jemoji plugin)

Emoji Cheatsheet

Highlighting

Highlighted text

1
<mark>Highlighted text</mark>

Keyboard Keys

Press Ctrl + C to copy.

1
Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy.

Math Expressions

Inline Math

This is inline math: \(E = mc^2\) and here’s another example with the quadratic formula \(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\).

1
$$ E = mc^2 $$

Block Math

\[\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}\]
1
2
3
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$

Equation Numbering

\[\begin{equation} E = mc^2 \label{eq:einstein} \end{equation}\]

You can reference the equation above using \eqref{eq:einstein}.

1
2
3
4
5
6
7
$$
\begin{equation}
E = mc^2 \label{eq:einstein}
\end{equation}
$$

Reference with \eqref{eq:einstein}

Math in Lists

  1. First equation: $$ a^2 + b^2 = c^2 $$
  2. Second equation: $$ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} $$
  3. Third equation: $$ \lim_{x \to \infty} \frac{1}{x} = 0 $$
1
2
3
1. \$$ a^2 + b^2 = c^2 $$
2. \$$ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} $$
3. \$$ \lim_{x \to \infty} \frac{1}{x} = 0 $$

Note: This site uses MathJax for rendering mathematical expressions. The Chirpy theme requires math: true in the front matter and specific syntax rules: use $$ math $$ for inline math (no blank lines), $$ math $$ with blank lines for block math, and escape the first $ in lists with \$$.


Footnotes

This text has a footnote1.

1
2
3
This text has a footnote[^1].

[^1]: This is the footnote content.

Comments

1
<!-- This is a comment that won't be visible -->

Collapsible Sections

Click to expand This content is hidden by default and can be expanded by clicking the summary. - Item 1 - Item 2 - Item 3 Code example:
function example() {
    console.log("Hello from collapsible section!");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
<details>
<summary>Click to expand</summary>

This content is hidden by default.

Code example:

<pre><code>function example() {
    console.log("Hello from collapsible section!");
}
</code></pre>

</details>

Custom ID Headers

Link to custom header

1
2
### Custom ID Headers {#custom-header}
[Link to custom header](#custom-header)

Choose the right Markdown editor for your workflow:

Online Editors

  • StackEdit - Full-featured online editor with live preview, export to HTML/PDF, and cloud sync
  • Dillinger - Clean web-based editor with export to HTML, styled HTML, PDF, and Markdown
  • HackMD - Collaborative editor with real-time sync, presentation mode, and team features

Desktop Applications

  • Typora - WYSIWYG editor with seamless live preview and export capabilities
  • Obsidian - Knowledge management with Markdown support and graph visualization

IDE Extensions

  • Vim Markdown - Vim plugin for Markdown syntax highlighting and folding

Markdown Flavors

Different platforms use variations of Markdown with additional features:

CommonMark

Standardized specification for consistent Markdown parsing across platforms. Visit the CommonMark spec for complete documentation.

GitHub Flavored Markdown (GFM)

Extends CommonMark with:

  • Tables
  • Task lists
  • Strikethrough
  • Autolinks
  • Syntax highlighting in code blocks

Extended Syntax

Many processors support additional features:

  • Footnotes
  • Definition lists
  • Table alignment
  • Abbreviations
  • Math expressions (LaTeX)

Note: Always check which Markdown flavor your target platform supports.

Best Practices

  1. Use consistent formatting throughout your document
  2. Add blank lines around headers and sections for readability
  3. Use descriptive alt text for images
  4. Include titles for links when helpful
  5. Test your markdown in your target renderer
  6. Use reference links for repeated URLs
  7. Indent nested lists properly with 2-4 spaces
  8. Use semantic headers (H1 for title, H2 for main sections)
  9. Keep line length reasonable (80-120 characters)
  10. Preview before publishing to catch formatting issues

Conclusion

This comprehensive markdown cheatsheet covers all essential syntax from basic text formatting to advanced features like math expressions and collapsible sections. Bookmark this reference for quick lookup while writing documentation, README files, or blog posts. Remember to test your markdown in your target environment since different renderers may have slight variations in support.

For more comprehensive guides and tutorials, visit The Markdown Guide - the definitive resource for learning Markdown.

  1. This is the footnote content. ↩︎

This post is licensed under CC BY 4.0 by the author.