How to Escape Backticks in Inline Markdown Code?

In markdown, you can make a backtick (`) render within inline code by wrapping the code in double (or more) backticks (``), for example, like so:

Markdown Output
``f`o`o`` f`o`o
`` f`o`o `` f`o`o
`` `foo `` `foo
`` foo` `` foo`
`` `foo` `` `foo`
```f`o``o``` f`o``o
``` f`o``o ``` f`o``o
``` ``foo ``` ``foo
``` foo`` ``` foo``
``` ``foo`` ``` ``foo``

As you can see from the examples above, the following rules apply:

  • To render a backtick at the start or end of your inline code, you must add a single space on each side of the text (e.g. `` `foo` ``). For all other cases, the space after double backticks (``) is optional (e.g. ``fo`o`` is same as `` fo`o ``);
  • You can wrap your inline code in more than double backticks (e.g. ``` ``foo`` ```). This is needed when you have a different number of surrounding backticks than the ones you wish to render, so that the interpreter can correctly render them.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.