# Markdown cheat sheet

Every markdown element with copyable syntax: core markdown, GitHub Flavored Markdown (tables, task lists, strikethrough, footnotes), alerts, emoji and mermaid diagrams. Rendered version with live previews: https://docs-md.com/markdown-cheat-sheet (updated 2026-10-20).

## Markdown syntax at a glance

| Element | Syntax | Note |
| --- | --- | --- |
| Heading | `# H1  ## H2  ### H3` | Up to six #; put a space after them. |
| Bold | `**bold text**` |  |
| Italic | `*italic* or _italic_` |  |
| Bold and italic | `***both***` |  |
| Strikethrough | `~~deleted~~` | GitHub Flavored Markdown (GFM). |
| Inline code | `` `code` `` |  |
| Code block | ```` ```js ⏎ code ⏎ ``` ```` | The word after the backticks sets the highlighting language. |
| Link | `[text](https://example.com)` |  |
| Image | `![alt text](image.png)` |  |
| Bulleted list | `- item` | * and + work too. |
| Numbered list | `1. item` |  |
| Task list | `- [ ] to do ⏎ - [x] done` | GFM. |
| Blockquote | `> quoted text` |  |
| Table | `\| A \| B \| ⏎ \| --- \| --- \| ⏎ \| 1 \| 2 \|` | GFM. Colons in the second row set alignment. |
| Horizontal rule | `---` |  |
| Line break | `line one\ ⏎ line two` | A backslash or two trailing spaces at the end of the line. |
| Footnote | `Text[^1] ⏎  ⏎ [^1]: The note.` | GFM. |
| Escape a character | `\*not italic\*` | A backslash before any markdown symbol. |
| Diagram | ```` ```mermaid ⏎ flowchart LR ⏎   A --> B ⏎ ``` ```` | Renders on GitHub, GitLab and Docs MD. |

## Headings

### Six levels

```markdown
# H1 — page title
## H2 — section
### H3 — subsection
#### H4
##### H5
###### H6
```

One H1 per document is the convention. The alternative "underline" syntax (=== / ---) only covers H1 and H2 — the # form is preferred.

## Emphasis

### Bold, italic, both

```markdown
**bold** and *italic* and ***bold italic***
```

Underscores work too (__bold__, _italic_), but asterisks survive mid-word: fan**tas**tic.

### Strikethrough (GFM)

```markdown
~~crossed out~~
```

## Lists

### Unordered

```markdown
- First item
- Second item
  - Nested (indent 2 spaces)
- Third item
```

### Ordered

```markdown
1. Step one
2. Step two
1. The numbers you type don't matter — renderers count for you
```

### Task list (GFM)

```markdown
- [x] Ship the feature
- [ ] Write the docs
- [ ] Tell someone
```

## Links & images

### Inline link

```markdown
[link text](https://docs-md.com "optional hover title")
```

### Image

```markdown
![alt text describing the image](https://docs-md.com/favicon.ico)
```

An image is a link with a ! in front. Alt text matters: screen readers read it, and it shows when the image breaks.

### Autolink (GFM)

```markdown
Bare URLs become links: https://docs-md.com
```

### Reference-style

```markdown
Long documents read better with [named references][docs].

[docs]: https://docs-md.com
```

Definitions can live anywhere in the file — conventionally at the bottom.

## Anchor links

A link to a heading on the same page. The target is the heading text as a slug: lowercase, spaces to hyphens, punctuation removed.

### Link to a heading

```markdown
## Getting Started

Jump to [Getting Started](#getting-started) or [Step 2: Install](#step-2-install).
```

Slug rules on GitHub: lowercase everything, drop punctuation except hyphens and underscores, turn spaces into hyphens, and add -1, -2 to duplicate headings. "Step 2: Install" becomes #step-2-install.

### Custom anchor with HTML

```markdown
<a id="custom-target"></a>
## Any heading text

[Go there](#custom-target)
```

When the heading text might change, pin an explicit id with an empty <a> tag above it. Works wherever inline HTML is allowed (GitHub, GitLab, most static site generators).

## Code

### Inline code

```markdown
Run `npm install` before `npm run dev`.
```

### Fenced block with language

````markdown
```ts
function greet(name: string) {
  return `Hello, ${name}`;
}
```
````

The language tag after ``` turns on syntax highlighting. Common tags: js, ts, python, bash, json, sql, diff.

### Fence inside a fence

`````markdown
````md
To show a code block inside a code block,
use more backticks on the outside:
```js
console.log("nested");
```
````
`````

## Tables (GFM)

### Basic table with alignment

```markdown
| Left | Center | Right |
| :--- | :----: | ----: |
| a    |   b    |     c |
| d    |   e    |     f |
```

Colons in the separator row control alignment. Escape literal pipes in cells as \|. Need to build one fast? Use the table generator below.

## Blockquotes

### Quote and nesting

```markdown
> A quoted paragraph.
>
> > Nested quotes work too.
>
> Back to the first level — **formatting works inside**.
```

Prefix every line with > (a lone > keeps a multi-paragraph quote together). GitHub turns > [!NOTE] / [!WARNING] quotes into coloured alerts.

## Alerts (GitHub)

A blockquote whose first line is [!TYPE] renders as a coloured callout on GitHub. Five types: NOTE, TIP, IMPORTANT, WARNING, CAUTION.

### The five alert types

```markdown
> [!NOTE]
> Useful information the reader should know.

> [!TIP]
> Advice for doing something better.

> [!IMPORTANT]
> Key information needed to succeed.

> [!WARNING]
> Urgent info that needs immediate attention.

> [!CAUTION]
> Negative consequences of an action.
```

Rendered as coloured boxes with icons on GitHub (READMEs, issues, PRs, discussions) and GitLab. Everywhere else — VS Code preview, Slack, Discord, Notion, most static site generators — the literal text "[!NOTE]" shows inside a plain blockquote, which is roughly what the preview on the right approximates.

## Structure & spacing

### Horizontal rule

```markdown
Above the line.

---

Below the line.
```

Three or more hyphens on their own line, with blank lines around them (otherwise --- under text becomes an H2).

### Line break vs. new paragraph

```markdown
End a line with two spaces  
for a line break in the same paragraph.

A blank line starts a new paragraph.
```

A backslash at the end of a line also forces a break and is easier to see than trailing spaces.

### Escaping characters

```markdown
\*not italic\* and \# not a heading and \| not a table pipe
```

## Footnotes (GFM)

### Footnote reference and definition

```markdown
Markdown was created in 2004.[^1]

[^1]: By John Gruber, with Aaron Swartz contributing to the syntax.
```

Supported on GitHub and most modern renderers; not part of original markdown.

## Emoji

### Shortcodes and literal emoji

```markdown
Ship it :tada: :rocket: — or paste the character directly: 🎉 🚀
```

Shortcodes like :tada: are not markdown: GitHub, GitLab, Slack and Discord expand them; CommonMark renderers, VS Code preview and most static site generators print the colons. Pasting the actual emoji character works everywhere.

## Mermaid diagrams

### Flowchart from a code fence

````markdown
```mermaid
graph LR
  A[Write markdown] --> B{Share it?}
  B -->|yes| C[Get a link]
  B -->|no| D[Keep local]
```
````

Supported on GitHub, GitLab, and Docs MD share pages. Also handles sequence diagrams, gantt charts, and ER diagrams.

## Inline HTML

### When markdown runs out

```markdown
Markdown has no underline, so use <u>HTML</u>, <sub>subscript</sub>, <sup>superscript</sup>, or <kbd>Ctrl</kbd>+<kbd>C</kbd>.
```

Most renderers pass HTML through (GitHub sanitizes scripts and styles). The preview on this page strips raw HTML, so check the result on your target platform.

### Keyboard keys with <kbd>

```markdown
Press <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> to open the command palette.
```

GitHub styles <kbd> as a small key cap. There is no markdown-native syntax for keys; backticks (`Ctrl`) are the plain-text fallback that works everywhere.

### Collapsible section with <details>

```markdown
<details>
<summary>Click to expand</summary>

Hidden content — **markdown works here** if you leave a blank line after the summary.

</details>
```

Supported on GitHub, GitLab and most docs sites. Add <details open> to start expanded. Not supported in Slack, Discord or Notion.

## Frequently asked questions

### What is a markdown cheat sheet?

A one-page reference of every markdown element with the syntax and the rendered result side by side, so you can copy the exact characters instead of guessing. This one covers core markdown, GitHub Flavored Markdown (tables, task lists, strikethrough, footnotes), and mermaid diagrams.

### How do I make text bold or italic in markdown?

Wrap text in double asterisks for bold (**bold**) and single asterisks or underscores for italic (*italic* or _italic_). Triple asterisks give bold italic. Underscores inside a word do not trigger emphasis on GitHub, so asterisks are the safer default.

### How do I add a link or an image?

A link is [text](https://example.com) and an image is the same with a leading exclamation mark: ![alt text](image.png). Add a tooltip with a quoted title after the URL. Reference-style links ([text][id] plus [id]: url on its own line) keep long documents readable.

### How do I write a code block?

Put the code between two lines of three backticks. Add a language name right after the opening backticks (```js) to get syntax highlighting. Use single backticks for inline code.

### How do I make a table in markdown?

Separate columns with pipes and add a line of dashes under the header row. Colons in that separator line set alignment: :--- left, :---: center, ---: right. Tables are a GFM extension supported by GitHub, GitLab, and most renderers.

### What is the difference between Markdown and GitHub Flavored Markdown?

GitHub Flavored Markdown (GFM) is the original markdown plus tables, task lists, strikethrough, autolinks, and footnotes, with a formal spec built on CommonMark. Nearly every modern renderer supports GFM, so it is what people usually mean by "markdown". GitHub itself adds alerts, emoji shortcodes and mermaid on top of GFM.

### Which Markdown works in Slack, Discord and Notion?

Each one is a different dialect. Discord supports most of the basics (**bold**, *italic*, code fences, headings, quotes) but has no tables or images and uses __underscores__ for underline. Slack is not markdown at all: *single asterisks* are bold, _underscores_ italic, ~tildes~ strikethrough, and [text](url) links only work in the composer with the markup preference on. Notion converts markdown as you type and on paste, including tables and task lists. Check the per-platform sheets before pasting.
