Markdown Tips & Tricks

Written by Last updated

Markdown looks small, but it has several moves that most people never learn: how to show a backtick inside code, hide a section, make an image clickable or link to a heading. Each trick below has an example you can copy.

Not a trick, a rule? Portability and accessibility rules are in Markdown Best Practices. Choices such as heading case are in the Markdown Style Guide. Need the basics first? See Markdown Basics.

Open EditorDownload PDF

Quick index

# Trick Works in
1 Show a backtick inside inline code CommonMark
2 Show a code fence inside a code block CommonMark
3 Put a code block inside a list item CommonMark
4 Escape any special character CommonMark
5 Break a line without trailing spaces CommonMark
6 Keep long URLs out of your text CommonMark
7 Make an image a link CommonMark
8 Resize an image HTML, where allowed
9 Link to a heading GitHub and most docs sites
10 Collapse a section HTML, where allowed
11 Leave a hidden comment HTML comment
12 Show keyboard keys HTML, where allowed
13 Add a footnote GitHub, some other tools
14 Add a note or warning box GitHub
15 Add a task list GFM

"CommonMark" means it works in any compliant parser. The others depend on the platform, so test them where you will publish. See the Markdown Reference for the support table.

Code tricks

1. Show a backtick inside inline code#

Use a longer run of backticks to open and close the code span, with a space inside the edges.

Use `` `code` `` to make inline code.

CommonMark strips one space from each edge, so this renders as `code` in code style.

2. Show a code fence inside a code block#

A fence closes only on a fence at least as long as the one that opened it. To show triple backticks, wrap them in four.

````markdown
```js
console.log("hi");
```
````

You can also use ~~~ for the outer fence.

3. Put a code block inside a list item#

Indent the fence to line up with the item text, and leave a blank line before it.

1. Install the package:

   ```bash
   npm install example
   ```

2. Start the app.

Under 1. that is 3 spaces. Under - it is 2. If the code block drops out of the list, the indent is wrong. See the CommonMark Guide for why.

Text tricks

4. Escape any special character#

A backslash makes the next character literal.

You type You get
\*not italic\* *not italic*
1\. Not a list 1. Not a list
\# Not a heading # Not a heading
\[not a link\] [not a link]

Inside a table cell, a pipe must be written as \|. See Markdown Tables. More in Escaping Characters.

5. Break a line without trailing spaces#

Two trailing spaces make a line break, but they are invisible and many editors strip them. End the line with a backslash instead.

First line\
Second line

The backslash break is part of CommonMark, but some older parsers do not support it, so test the platforms you target. See Line Breaks.

6. Keep long URLs out of your text#

Reference-style links put the URL at the bottom, so paragraphs stay readable and a repeated URL is defined once.

Read the [spec][cm] and the [GFM spec][gfm].

[cm]: https://spec.commonmark.org/
[gfm]: https://github.github.com/gfm/

Layout tricks

10. Collapse a section#

<details> hides content until the reader clicks. Leave a blank line after <summary>, or the Markdown inside will not render.

<details>
<summary>Show the full config</summary>

- Item one
- Item two

</details>

Good for long logs and optional steps. GitHub supports collapsed sections, but some platforms strip these tags.

11. Leave a hidden comment#

An HTML comment does not render.

<!-- TODO: add screenshot after release -->

It is still in the file and in the page source, so do not put secrets in it.

12. Show keyboard keys#

Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save.

13. Add a footnote#

GitHub supports this.[^1]

[^1]: Footnotes are not part of CommonMark or the GFM spec.

GitHub renders it, except in wikis. Other tools need a footnote extension. See Footnotes.

14. Add a note or warning box#

GitHub renders alerts from a blockquote with a type tag. It supports five types: NOTE, TIP, IMPORTANT, WARNING and CAUTION.

> [!NOTE]
> Useful information.

> [!WARNING]
> Urgent information.

These show as plain blockquotes elsewhere. See GitHub Markdown.

15. Add a task list#

- [x] Write the draft
- [ ] Check the links

Part of GFM. Build one with the Task List Generator. See Task Lists.

Editor moves

These save time when writing Markdown, and they are not Markdown syntax.

Move How
Open preview in VS Code Ctrl+Shift+V (Cmd+Shift+V on Mac)
Preview beside the editor Ctrl+K V (Cmd+K V on Mac)
Replace across files Find in Files, with the replace field open
Reuse a structure Save it as a snippet

More in the VS Code Markdown guide.

For content that is already written elsewhere, convert it instead of retyping: HTML to Markdown, or tidy a table with the Markdown Table Formatter.

Frequently Asked Questions

  1. 1

    How do I show a backtick inside inline code in Markdown?

    Open and close the code span with two backticks and put a space inside each edge. See trick 1.

  2. 2

    How do I make a collapsible section in Markdown?

    Use the HTML <details> and <summary> tags, and leave a blank line after <summary>. Some platforms strip HTML, so test where you publish. See trick 10.

  3. 3

    Can I change the size of an image in Markdown?

    Not with standard syntax. Use an HTML <img> tag with width, where the platform allows it. See trick 8.

  4. 4

    Why does my code block fall out of my list?

    The fence is not indented to the list item's text. Under 1. use 3 spaces, under - use 2.

  5. 5

    Do these tricks work everywhere?

    Tricks 1 to 7 are standard Markdown. The rest depend on HTML support or on GitHub. The index above says which.