Skip to main content
Markdown Syntax:

How to escape backticks in Markdown

Summary

This guide explains how to escape backticks in Markdown to ensure inline code and code blocks display correctly, even when your content includes backticks itself. Learn the proper syntax to display backticks without breaking your Markdown formatting.

Introduction #

In Markdown, backticks (`) are used to indicate code. When you want to display a snippet of code inline or in a code block, you use one or more backticks to wrap the text. Inline code uses single backticks, while code blocks use triple backticks.

Problems arise when your actual code contains backticks. If not handled properly, Markdown may misinterpret the code and break your formatting. This article explains how to escape backticks so that your code is displayed exactly as intended, both inline and in fenced code blocks. Let’s have a look at how to tackle such problems.

How to escape backticks in inline code #

If your code contains a backtick and you want to display it as part of the inline code, you can wrap the entire snippet in double backticks instead of a single one. This tells the Markdown parser to treat everything inside as code, including the single backtick.

Single backticks #

Inline code example with single backticks inside:

  ``Use the `code` tag``

This will render as:

Use the `code` tag

Double backticks #

If your code contains double backticks, you can surround it with triple backticks, and so on.

Inline code example with double backticks inside:

  ```Here is ``double`` backtick```

This will render as:

Here is ``double`` backtick

Multiple backticks #

For inline code, use double, triple, quadruple, quintuple, etc. backticks to render one, two, three, four, or more backticks in markdown. Here’s the logic:

AmountMarkdownRenders as
1 backtick`` ` ```
2 backticks``` `` `````
3 backticks```` ``` ```````
4 backticks````` ```` `````````
5 backticks`````` ````` ```````````

The general rule is to use more backticks on the outside than any number used inside the code.

How to escape backticks in code blocks #

Code blocks in Markdown are fenced using three backticks. But what happens when your code itself contains three backticks? In that case, you need to use a longer fence than the maximum sequence of backticks within your code.

If your code contains triple backticks, you can wrap the block in four backticks:

  ````
  ```
  const example = `Hello`;
  ```
  ````

This will render as:

```
const example = `Hello`;
```

The general rule is to always use a longer sequence of backticks to fence the block than the longest run of backticks inside the code.

Tips for working with backticks in Markdown #

  1. Always count the number of backticks and use more for the wrapper.
  2. Be aware of how your Markdown flavor handles rendering.
  3. If the code includes multiple nested backticks, test your output visually to ensure correctness.

You may also consider using HTML code blocks for maximum compatibility.

FAQ's #

Most common questions and brief, easy-to-understand answers on the topic:

How do I escape a single backtick in Markdown?

You can wrap the backtick with double backticks for inline code or use a longer sequence of backticks for code blocks.

Can I use more than three backticks for code blocks in Markdown?

Yes. You can use more than three backticks to surround code that includes triple backticks inside the block.

Does escaping backticks work the same in all Markdown renderers?

Most renderers behave similarly, but some may have subtle differences. Always test your Markdown in your target environment.

What are backticks used for in Markdown?

Backticks are used to denote inline code and to create fenced code blocks for displaying source code in Markdown.

Further readings #

Sources and recommended, further resources on the topic:

Author

Jonas Jared Jacek • J15k

Jonas Jared Jacek (J15k)

Jonas works as project manager, web designer, and web developer since 2001. On top of that, he is a Linux system administrator with a broad interest in things related to programming, architecture, and design. See: https://www.j15k.com/

License

How to escape backticks in Markdown by Jonas Jared Jacek is licensed under CC BY-SA 4.0.

This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:

<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.ditig.com/how-to-escape-markdown-backticks">How to escape backticks in Markdown</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>

For more information see the Ditig legal page.

All Topics

Random Quote

“I avoid the cesspools of the Internet – Twitter, Slashdot, whatever troll-infested things that try to get a rise out of you.”

Linus Torvalds  Finnish software engineer, creator of the Linux kernel and GitiTWire, - IT quotes