Markdown Cheat Sheet
Last updated
Headings
Put a space after the # signs. The number of signs sets the level, from 1 to 6.
| Element | Markdown | Result |
|---|---|---|
| Heading 1 | # Page title | Top-level heading, <h1> |
| Heading 2 | ## Section | Section heading, <h2> |
| Heading 3 | ### Subsection | Subsection heading, <h3> |
| Headings 4 to 6 | #### Level 4
##### Level 5
###### Level 6 | <h4>, <h5> and <h6> |
| Heading 1, alternate | Page title
========== | <h1>, the same as # Page title |
| Heading 2, alternate | Section
------- | <h2>, the same as ## Section |
| Closing hashes | ## Section ## | <h2>Section</h2>; trailing # signs are dropped |
| Missing space | #Not a heading | A plain paragraph. The space after # is required |
Bold, italic and strikethrough
Asterisks work anywhere, even inside a word. Underscores only work at word boundaries, so snake_case stays as typed.
| Element | Markdown | Result |
|---|---|---|
| Bold | **bold text** | Bold, <strong>bold text</strong> |
| Bold, underscores | __bold text__ | Bold, the same as above |
| Italic | *italic text* | Italic, <em>italic text</em> |
| Italic, underscores | _italic text_ | Italic, the same as above |
| Bold and italic | ***bold and italic*** | <em><strong>bold and italic</strong></em> |
| Bold inside a word | un**believ**able | Only the middle of the word is bold |
| Underscores in a word | snake_case_name | Plain text, no italic |
| Strikethrough (GFM) | ~~no longer true~~ | Crossed out, <del>no longer true</del> |
| Underline | <ins>underlined</ins> | Underlined text. Markdown has no underline syntax, so this is HTML |
| Highlight | <mark>highlighted</mark> | Highlighted text where the site allows the <mark> tag. Markdown has no highlight syntax |
Line breaks and paragraphs
Pressing Enter once inside a paragraph does not start a new line in the output. Use one of these instead.
| Element | Markdown | Result |
|---|---|---|
| New paragraph | First paragraph.
Second paragraph. | Two paragraphs. A blank line separates them |
| Break: two spaces | Roses are red,
Violets are blue. | One paragraph with a <br> after red,. The first line ends with two spaces, which you cannot see |
| Break: backslash | Roses are red,\
Violets are blue. | The same <br>, with a marker you can see. Works in CommonMark and on GitHub |
| Break: HTML | Roses are red,<br>Violets are blue. | The same <br>. Also works inside a table cell |
| Single newline | Roses are red,
Violets are blue. | One line: Roses are red, Violets are blue. GitHub issues and comments keep the break; .md files do not |
| Extra blank lines | One.
Two. | The same as one blank line. For more space, put <br> on its own line |
Lists
Indent a nested item so it lines up with the text of the item above: 2 spaces under - , 3 spaces under 1. .
| Element | Markdown | Result |
|---|---|---|
| Bulleted list | - Apples
- Pears
- Plums | A bulleted list, <ul> with three <li> |
| Other bullets | * Apples
+ Pears | * and + also make bullets. Switching the character starts a new list |
| Numbered list | 1. Install
2. Configure
3. Run | A numbered list, <ol> |
| Lazy numbering | 1. Install
1. Configure
1. Run | Still numbered 1, 2, 3. Only the first number counts |
| Start at a number | 7. Seventh
8. Eighth | <ol start="7">, numbered from 7 |
| Nested list | - Fruit
- Apple
- Pear
- Vegetables | A list inside the first item |
| Nested, numbered | 1. Download
- Windows
- macOS
2. Install | Bullets inside step 1, indented 3 spaces |
| Paragraph in an item | - First item
More about the first item.
- Second item | Two paragraphs inside the first item |
| Code in an item | 1. Run this:
```bash
npm install
```
2. Start the app | A code block inside step 1, indented to the item's text |
Task lists (checkboxes)
A GitHub Flavored Markdown extension: a list item that starts with [ ] or [x] becomes a checkbox.
| Element | Markdown | Result |
|---|---|---|
| Empty checkbox | - [ ] Write tests | An unticked checkbox |
| Ticked checkbox | - [x] Write tests | A ticked checkbox. [X] works too |
| Checklist | - [x] Draft
- [ ] Review
- [ ] Publish | One ticked box and two empty ones. In GitHub issues and pull requests you can tick them with a click |
| Nested tasks | - [ ] Release
- [x] Tag the commit
- [ ] Write the notes | Two sub-tasks under the first box |
| Missing space | - [] Write tests | A plain bullet that reads [] Write tests. The brackets need a space or an x |
Links
The link text goes in square brackets and the address in parentheses right after it, with no space between them.
| Element | Markdown | Result |
|---|---|---|
| Inline link | [Coddy](https://coddy.tech) | <a href="https://coddy.tech">Coddy</a> |
| Link with a title | [Coddy](https://coddy.tech "Learn to code") | The same link. The title shows as a tooltip on hover |
| URL in angle brackets | <https://coddy.tech> | The URL itself, as a link |
| Bare URL (GFM) | https://coddy.tech | A link on GitHub and other GFM sites, which also link www. addresses. Plain text in strict CommonMark |
| Email link | <hello@example.com> | A mailto: link |
| Reference link | Read the [docs][1].
[1]: https://example.com/docs | docs links to the URL. The [1]: line is not shown |
| Shortcut reference | See [GitHub].
[GitHub]: https://github.com | GitHub links to the URL |
| Relative link | [Install guide](docs/install.md) | A link to a file relative to this one. On GitHub it opens the file in the repository |
| Link to a heading | [Jump to setup](#getting-started) | Scrolls to ## Getting Started on the same page |
| Heading IDs | ## Getting Started! | Gets the ID getting-started on GitHub: lower case, spaces become hyphens, punctuation other than - and _ is dropped |
| Heading in another file | [Requirements](docs/install.md#requirements) | Opens the file at that heading |
| Spaces in the URL | [Report](my%20report.pdf) | Write each space as %20, or wrap the URL in angle brackets: [Report](<my report.pdf>) |
| Open in a new tab | <a href="https://coddy.tech" target="_blank">Coddy</a> | Markdown has no syntax for this. The HTML works where the site keeps the target attribute |
Images
An image is a link with ! in front. The text in the brackets becomes the alt text, which screen readers read aloud.
| Element | Markdown | Result |
|---|---|---|
| Image |  | <img src="cat.png" alt="A cat asleep on a sofa"> |
| Image with a title |  | The same image with a tooltip on hover |
| Image from a URL |  | Loads the image from the web |
| Linked image | [](https://coddy.tech) | An image that opens the link when clicked |
| Reference image | ![Logo][logo]
[logo]: images/logo.png | The same as an inline image, with the URL defined once below |
| Image size | <img src="logo.png" alt="Logo" width="200"> | The image, 200 pixels wide. Plain Markdown has no size syntax, so this is an HTML <img> tag |
| Centered image | <p align="center">
<img src="logo.png" alt="Logo" width="200">
</p> | A centered image, as seen in many GitHub README files |
Code and code blocks
Backticks mark code inside a line; a fence of three backticks marks a block. Nothing inside code is formatted.
| Element | Markdown | Result |
|---|---|---|
| Inline code | Run `npm install` first. | npm install in a monospace font, as <code> |
| Backtick inside code | ``Use `git` here`` | The code Use `git` here. Wrap it in more backticks than it contains |
| Code block | ```
npm install
npm run dev
``` | A block, <pre><code>, with the line breaks kept |
| Syntax highlighting | ```python
def greet(name):
return f"Hello, {name}"
``` | A Python block with colored syntax. Common names: js, ts, python, bash, json, html, css, sql |
| Tilde fence | ~~~js
console.log("hi");
~~~ | The same as a backtick fence |
| Indented code | const total = 42; | A code block made by 4 spaces of indent, after a blank line |
| Diff block | ```diff
- const x = 1;
+ const x = 2;
``` | Removed lines in red and added lines in green on GitHub |
| Fence inside a block | ````markdown
```js
let a = 1;
```
```` | A block that shows the inner fence as text. The outer fence needs more backticks than the inner one |
Tables
A GitHub Flavored Markdown extension. The second line, the delimiter row, turns the first line into a header. It must have the same number of cells as the header, or no table is made.
| Element | Markdown | Result |
|---|---|---|
| Table | | Name | Role |
| ----- | ------ |
| Ada | Admin |
| Linus | Editor | | A table with a header row and two rows |
| Column alignment | | Left | Center | Right |
| :--- | :----: | ----: |
| a | b | c | | Colons set the alignment: left, centered, right |
| No outer pipes | Name | Role
--- | ---
Ada | Admin | The same table. The pipes at the start and end of a line are optional |
| Column width | | a | b |
|---|---|
| 1 | 2 | | Widths come from the content. The number of hyphens does not matter, and the pipes need not line up |
| Formatting in cells | | Command | Does |
| --- | --- |
| `git status` | Shows **changed** files | | Code, bold, links and images all work inside cells |
| Pipe inside a cell | | Operator | Meaning |
| --- | --- |
| `a \| b` | a or b | | The cell shows a | b. Escape the pipe as \|, even inside code |
| Line break in a cell | | Step | Notes |
| --- | --- |
| 1 | First line<br>Second line | | Two lines in one cell. A real newline would end the row |
| Merged cells | <td colspan="2">Both columns</td> | Markdown tables cannot merge cells. Write the table in HTML with colspan or rowspan |
Blockquotes
Start each line with >. A blockquote can hold any other Markdown.
| Element | Markdown | Result |
|---|---|---|
| Blockquote | > Simple is better than complex. | An indented quote, <blockquote> |
| Several paragraphs | > First paragraph.
>
> Second paragraph. | One quote with two paragraphs. The bare > line keeps them together |
| Nested quote | > The reply
>> The original message | A quote inside a quote |
| Other elements inside | > #### Note
> - Back up first
> - Then upgrade | A heading and a list inside the quote |
| Alert (GitHub) | > [!NOTE]
> Requires Node 20 or later. | A colored Note box on GitHub. The other types are [!TIP], [!IMPORTANT], [!WARNING] and [!CAUTION] |
Horizontal rules
Three or more hyphens, asterisks or underscores alone on a line draw a line across the page.
| Element | Markdown | Result |
|---|---|---|
| Rule | --- | A horizontal line, <hr> |
| Other forms | ***
___ | Two more rules |
| Rule after text | Some text
--- | A paragraph, then a rule. Keep the blank line |
| Missing blank line | Some text
--- | A level 2 heading, not a rule: --- under a line of text underlines it |
Footnotes
Supported on GitHub, GitLab and many static site generators. Strict CommonMark has no footnotes.
| Element | Markdown | Result |
|---|---|---|
| Footnote | Markdown dates from 2004.[^1]
[^1]: John Gruber created it, with Aaron Swartz. | A superscript 1 that links to the note, listed at the bottom of the page |
| Named footnote | See the spec.[^spec]
[^spec]: https://spec.commonmark.org | Labels can be words, but the notes are still numbered 1, 2, 3 in order of use |
| Where to define it | [^1]: The text of the note. | The definition can sit anywhere in the file. It always renders at the end |
Escaping characters
A backslash before a punctuation character prints the character itself instead of formatting.
| Element | Markdown | Result |
|---|---|---|
| Literal asterisks | \*not italic\* | Plain text with the asterisks: *not italic* |
| Literal hash | \# Not a heading | A paragraph that starts with # |
| Number and a period | 2024\. A good year. | A paragraph, not a list that starts at 2024 |
| Literal brackets | \[not a link\](page.md) | The brackets and parentheses as typed |
| Literal backtick | \` | One backtick |
| Literal backslash | \\ | One backslash |
| What can be escaped | \ ` * _ {} [] () <> # + - . ! | | Any ASCII punctuation. A backslash before a letter or digit stays a backslash |
| HTML entities | © 2026 & <div> | © 2026 & <div>, as text |
| No escaping in code | `*stars*` | The code *stars* as typed. Inside code a backslash is a plain character |
HTML inside Markdown
Most renderers pass HTML through, so a tag covers what Markdown has no syntax for. GitHub removes unsafe HTML such as <script>, <style>, <iframe> and style attributes.
| Element | Markdown | Result |
|---|---|---|
| Keyboard keys | Press <kbd>Ctrl</kbd> + <kbd>C</kbd> | Ctrl and C drawn as keys |
| Sub and superscript | H<sub>2</sub>O and x<sup>2</sup> | H₂O and x² |
| Collapsible section | <details>
<summary>Show the answer</summary>
The answer is **42**.
</details> | A section that opens on click. The blank lines let the Markdown inside it render |
| Markdown in an HTML block | <div>
**not bold**
</div> | **not bold** as typed. Markdown is not read inside an HTML block until a blank line ends the block |
| Colored text | <span style="color: red">red</span> | Red text on sites that allow inline styles. GitHub removes the style attribute |
Comments
Markdown has no comment syntax. Two tricks keep text off the rendered page.
| Element | Markdown | Result |
|---|---|---|
| Hidden comment | [//]: # (This line is never shown) | Nothing. The line is a link definition that no link uses, so it never reaches the HTML |
| Alternate form | [comment]: <> (Also hidden) | Nothing, by the same trick |
| HTML comment | <!-- TODO: add screenshots --> | Nothing on the page, but the comment stays in the HTML source |
| Multi-line comment | <!--
This whole block
is hidden
--> | Nothing on the page |
| Placement | Some text.
[//]: # (comment)
More text. | Two paragraphs. The comment line needs a blank line before it, or it shows as text |
GitHub Flavored Markdown and GitHub extras
GitHub Flavored Markdown (GFM) is CommonMark plus tables, task lists, strikethrough and bare URL links. GitHub adds more on top.
| Feature | Markdown | Where it works |
|---|---|---|
| Tables | | a | b |
| --- | --- |
| 1 | 2 | | GFM: GitHub, GitLab and most documentation tools |
| Task lists | - [x] Done | GFM |
| Strikethrough | ~~text~~ | GFM |
| Bare URL links | www.coddy.tech | GFM |
| Code with a language | ```js
let a = 1;
``` | CommonMark and GFM. The colors come from the site |
| Footnotes | Text.[^1]
[^1]: Note. | GitHub and GitLab, though not in the GFM spec |
| Emoji | :rocket: :tada: | GitHub and GitLab turn shortcodes into emoji |
| Mentions | @octocat | GitHub: links the user and notifies them |
| Issue links | #123 | GitHub: links issue or pull request 123 in the same repository |
| Diagrams | ```mermaid
graph LR
A --> B
``` | GitHub and GitLab draw a Mermaid diagram |
| Math | $E = mc^2$
$$
\sum_{i=1}^{n} i
$$ | GitHub renders LaTeX math, inline between $ signs and as a block between $$ lines |
Every piece of Markdown syntax on one page, next to what it turns into. This Markdown cheat sheet covers the core syntax (headings, emphasis, line breaks, lists, links, images, code, blockquotes) and the GitHub Flavored Markdown extras: tables with alignment, task lists, strikethrough, bare URL links and footnotes, plus escaping, HTML and comments.
The examples follow CommonMark and GitHub Flavored Markdown, the rules GitHub, GitLab and most documentation tools build on. Where a site behaves differently, the row says so. To watch any example render as you type, paste it into the Markdown editor.
Markdown cheat sheet FAQ
How do I make a table in Markdown?
| Name | Role |, | --- | --- |, | Ada | Admin |. Colons in the delimiter row align a column: :--- left, :---: centered, ---: right. Tables are a GitHub Flavored Markdown feature, so they work on GitHub, GitLab and most documentation tools, but not in strict CommonMark.How do I add a new line in Markdown?
\), or write <br>. To start a new paragraph, leave a blank line. GitHub issues and comments are the exception: there a single newline already shows as a line break.How do I write a comment in Markdown?
[//]: # (your comment) on its own line, with a blank line before it, is a link definition that nothing uses, so it never reaches the page or the HTML. An HTML comment, <!-- your comment -->, is also hidden on the page but stays in the HTML source, where anyone who views the source can read it.How do I make a code block in Markdown?
```python, to get syntax highlighting. For code inside a sentence, wrap it in single backticks: `npm install`.How do I add a checkbox in Markdown?
[ ] for an empty box or [x] for a ticked one: - [ ] Review or - [x] Draft. Keep the space inside the empty brackets. Checkboxes are part of GitHub Flavored Markdown, and in GitHub issues and pull requests you can tick them with a click.How do I change the size of an image in Markdown?
 always shows the image at its own size. Use an HTML tag instead, such as <img src="image.png" alt="alt text" width="300">, which GitHub and most renderers accept. Set only the width or only the height to keep the proportions.How do I link to a heading in Markdown?
#: [Setup](#getting-started) jumps to ## Getting Started. GitHub builds the ID from the heading text in lower case, with spaces turned into hyphens and punctuation other than hyphens and underscores removed. For a heading in another file, put the ID after the file name: [Setup](docs/install.md#getting-started).What is a .md file?
.md and .markdown are the usual extensions, and README.md is the file GitHub shows on the front page of a repository. Any text editor opens one; GitHub, documentation sites and Markdown viewers render it as formatted text. To see a file rendered as you edit it, paste it into the Markdown editor.