How do I escape a backtick ` within a code block?

This is probably a duplicate, since I'm sure it's a common concern, but I can't find a question that addresses this specifically.

How do I write List'1 with the "1" character still in the code-text format?


Use four spaces before your code:


Or use double backticks: ``List`1`` produces List`1.

See http://daringfireball.net/projects/markdown/syntax, linked to from the formatting question box.

Note: Putting a single space on each side of the text will be necessary if you want to have a backtick at the beginning or the end of your code, e.g., foo`, `foo, or just `. This will keep it from consuming the first two closing backticks instead of the final two closing backticks.

`` foo` `` produces foo`
`` `foo `` produces `foo
`` ` `` produces single backtick `

You can put the space just on the side ending with a backtick, but then that space might get included in the in-line code (in GitHub Flavoured Markdown for example) which is why using a single space on each side of the code is generally preferred.

If you need to show extra backticks, enclose them with a higher number of them:

``` ``two backticks`` ``` produces ``two backticks``
  • 3
    How do you have two consecutive backticks in inline code?
    – asmeurer
    Jun 16 '13 at 16:44
  • 6
    @asmeurer: Wrap your inline code with triple backticks. !``! For triple or higher backticks, you can wrap your inline code with double backticks, rather than quadruple backticks (unless you need both triple and double backticks at different places). !```! vs !``!```!
    – Brian
    Jun 16 '13 at 19:09
  • 2
    As mentioned in the other answers to the question, you can simply escape backticks with a backslash `\` for inline formatting.
    – user163250
    Jun 5 '14 at 14:55
  • 10
    Extra spacing also required if you want a backtick at the start of your quote. I just wanted a backtick and nothing else in this answer so used `` ` `` (couldn't work out how to quote this in this comment though!) Jan 25 '16 at 21:05
  • 2
    sheesh, why can't inline/post markdown parsing be consistent with the comment markdown parsing?
    – wisbucky
    Jul 10 '19 at 22:29
  • 1
    @user163250 backsslash does not work inside a backticked section, it just renders as a backslash Nov 21 '19 at 12:30
  • 1
    Four-spaces which works for me (Redmine markdown) Dec 28 '20 at 7:28
  • The spaces!! That's what I was missing. Thanks so much! Oct 20 at 0:53

For GitHub, like for displaying a MySQL `table_name`, in regular text use \` (backslash backtick).

For showing backticks inside inline codeblocks `table_name`, use double backticks with extra spaces `` `table_name` `` around the inner single backticks.

To show the previous example explanation in an inline codeblock: `` `table_name` ``, surround the whole in three backticks with extra spaces, e.g. ``` `` `table_name` `` ```

(head a splode)

  • 10
    Thanks for pointing out that extra spaces are required!
    – CodeManX
    Aug 28 '14 at 20:40
  • 12
    And that continues for any number of backticks. If you are writing about how to use Prism syntax highlighting and want to display three backticks, you need to "escape" them with four backticks and a space. (i.e. ```` ```language_javascript ````)
    – Jedidja
    Mar 3 '15 at 18:53
  • 1
    A very cool trick; first time I hear about it!
    – mgol
    Sep 5 '16 at 22:13
  • An amusing secondary quest would be to display "symbol followed (or preceded) by space in inline code"... Eg. I want to represent the + and space sequence, apparently it is not possible (no-break space is collapsed as well :-/).
    – PhiLho
    Apr 24 '18 at 13:31

You can use an extra backtick at the start and end to make sure it escapes correctly:


When inline it will display as List`1.

Markdown provides backslash escapes for the following characters:

\   backslash
`   backtick
*   asterisk
_   underscore
{}  curly braces
[]  square brackets
()  parentheses
#   hash mark
+   plus sign
-   minus sign (hyphen)
.   dot
!   exclamation mark

for example, this:

## \\ \` \* \_ \{ \} \[ \] \( \) \# \+ \- \. \!


\ ` * _ { } [ ] ( ) # + - . !

Escaped codeblock, italics, bold, link, headings and list:

`not codeblock`, *not italics*, **not bold**, [not link](http://www.google.com)

# not h1

## not h2

### not h3

+ not ul

- not ul

  • 2
    I think the escape part of your answer is irrelevant since the OP is asking about how to escape inside an inline code block.
    – TWiStErRob
    Jul 16 '15 at 9:44
  • @TWiStErRob - The escape works in the codeblock. For example, List`1 is achieved using `List\`1`.
    – Mike
    Mar 5 '16 at 16:33
  • @suhail - The escape was the only method I could get to work for this: grep "docker-machine-`uname -s`-`uname -m`", so thanks!
    – Mike
    Mar 5 '16 at 16:36
  • 2
    @Mike I'm not even sure what I meant in retrospect, I was probably referencing the second half of the answer, because that's plain text, not code block (notice: no gray background). To clarify: the "put more ticks around the code than you want to escape" part of the answer is awesome, but the backslash-escape sequences are not useful within code blocks as I tried.
    – TWiStErRob
    Mar 5 '16 at 16:54

For fenced code blocks, the prescription is more backticks.

This Markdown

Example of Markdown syntax for fenced code block with triple back ticks

will be rendered like this

Example of Markdown syntax for fenced code block with triple back ticks
  • 1
    Another trick that works when wanting to quote a tripple backtick within a tripple backtick section, is to insert a ZWJ (Zero-Width-Joiner) character between two of the three backticks. Other zero-width unicode characters probably works as well. Jul 13 '19 at 20:10
  • 2
    This was the most helpful answer. Two other things: i) same technique works in github flavoured markdown. and ii) to take regular code and add four spaces as the start of every line, in sublime text (or other code editors), find and replace ^ (start of a line) with ^ (start of a line followed by four spaces). Works a treat!
    – stevec
    Apr 18 '20 at 14:56
  • 1
    This worked for me in BitBucket after trying a lot of the other suggestions!
    – CodeMonkey
    Nov 11 '20 at 15:32

Use <code> and HTML character entities instead. This is especially useful in situations where your code is already wrapping things in backticks (e.g., in Swift, enum { case `true` = 1 }).

HTML gives you three ways to specify a character entity for a backtick: &grave;, &#96;, & &#x60;.  The choice is yours.

The way to accomplish the example with this technique would be <code>List&grave;1</code>, resulting in List`1.  The markdown for List`List`1 would just be <code>List&grave;List&grave;1</code>.  It's a little messy, but not unbearable if you're used to reading/writing HTML.

While more cumbersome than normal Markdown, this approach is also much more compatible.  Some Markdown parsers don't like backslash-escapes; some will created nested code spans instead of working like @Brian's example; others will do other weird things; but the HTML approach will only fail if the Markdown parser has HTML turned completely off (which is exceedingly rare).

The general approach I take is “If I can't do it with Markdown, or if doing it in Markdown is a complicated mess of repeated symbols and tricks, just drop down to HTML for that use-case.”

Note that on SE sites, this only works in questions & answers, not comments (unfortunately! and somewhat negating my “exceedingly rate” analysis above!); HTML entities are displayed as plaintext in comments.


It's different in posts and in comments.

For posts


`` ` ``

Result (only for posts, not valid in comments): `



Result (only for posts, not valid in comments): `

For comments


Result (only for comments, not valid in posts): ```


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .