To escape a special character in Markdown, put a backslash directly before it: \*not italic\* prints the asterisks instead of making the text italic. In CommonMark, any ASCII punctuation character can be escaped this way. The exceptions matter more than the rule: backslashes do nothing inside code spans, code blocks, autolinks and raw HTML.
How Markdown escape characters work
Markdown escape characters work by placing a backslash in front of a punctuation mark so the parser treats that mark as plain text. The CommonMark spec says any ASCII punctuation character may be backslash-escaped, and escaped characters lose their usual Markdown meaning.
A backslash before anything else, such as a letter or a digit, stays in the output as a literal backslash. So \d shows \d, but \# shows #. Extra backslashes before punctuation cost nothing. Before a letter, they show up on the page.
GitHub Docs use this one: Let's rename \*our-new-project\* to \*our-old-project\*. Without the backslashes, the project names would render in italics.
Which characters can you escape?
The characters you can escape are the ones Markdown uses for syntax. John Gruber's original Markdown syntax lists twelve:
| Character | Name | Why you'd escape it |
|---|---|---|
\ |
backslash | to show a literal backslash (\\) |
` |
backtick | stops inline code from starting |
* |
asterisk | stops emphasis or a bullet |
_ |
underscore | stops emphasis |
{} |
curly braces | some extensions use them for attributes |
[] |
square brackets | stops a link from forming |
() |
parentheses | after brackets, stops a link URL |
# |
hash mark | stops a heading at the start of a line |
+ |
plus sign | stops a bullet at the start of a line |
- |
minus sign | stops a bullet or a horizontal rule |
. |
dot | stops a numbered list after a number |
! |
exclamation mark | stops an image before brackets |
The Markdown Guide adds angle brackets and the pipe to that list. CommonMark goes further and allows any ASCII punctuation, so \$, \~ and \| are all valid there.
Where you actually need to escape
Most special characters only need escaping where they would start something. A lone asterisk in the middle of "5 * 3" with spaces on both sides usually renders fine. Escape a character when it sits where syntax starts:
- Start of a line:
#,-,+,>and a number followed by a dot all begin block elements. - Paired around text:
*word*and_word_become emphasis. - Before brackets:
!turns[alt](url)into an image. - Inside tables:
|splits cells.
Underscores have a useful quirk. The CommonMark spec says emphasis with _ is not allowed inside words, so snake_case_name usually renders as written. Asterisks don't get that pass: intraword emphasis with * is permitted. My rule is to escape every asterisk, and to escape underscores only when they touch the start or end of a word.
The accidental numbered list
A line that starts with a year and a period can turn into a numbered list by accident. Gruber's own example is 1986. What a great season., and his fix is to escape the dot: 1986\. What a great season.
The Markdown Guide shows the same trick inside a bullet: - 1968\. A great year!. The CommonMark spec has a matching case where 1\. not a list renders as plain text. If your changelog or timeline suddenly restarts at "1.", this is the cause.
Where backslash escapes do not work
Backslash escapes are ignored in four places, and that is where most "why is my backslash showing" questions come from. The CommonMark spec says escapes do not work in code blocks, code spans, autolinks or raw HTML. They do work in URLs and link titles.
| Context | Does \ escape? |
What to do instead |
|---|---|---|
| Normal text | Yes | Backslash before the character |
| Link URL and title | Yes | Backslash works here too |
| Inline code span | No | Use a longer backtick fence |
| Fenced or indented code block | No | Nothing needed, content is literal |
Autolink like <https://...> |
No | Write a normal link instead |
| Raw HTML tag | No | Use HTML entities like < |
| GitHub issue or PR title | No, formatting still applies | Rephrase or leave it |
The last row is from GitHub Docs: Markdown formatting is not ignored in issue and pull request titles.
Backticks inside inline code
To show a backtick inside inline code, wrap the code in a longer run of backticks. The CommonMark spec uses double backticks around code that contains a single one. If the content starts or ends with a backtick, add a space inside the delimiters; the parser strips one space from each side when both ends have one.
Don't try `foo\`bar` inside a code span. The spec says all backslashes in code spans are literal, so that backslash prints and the backtick closes the span early.
Pipes inside table cells
A pipe inside a table cell needs a backslash, even inside inline code. The GFM spec says to include a pipe in a cell's content by escaping it, including inside other inline spans. That's a table-specific exception to the code span rule. If a table breaks for other reasons, see why a Markdown table is not rendering.
Using HTML entities instead of a backslash
HTML entities are the other way to print a special character, and they help where a backslash can't. CommonMark accepts references like * for a literal asterisk. There's a catch: the spec says an entity cannot replace * in emphasis delimiters, bullet markers or thematic breaks, and entities are not recognized inside code.
For < and &, you rarely need either method. Gruber wrote that Markdown takes care of the escaping for these two characters in normal text. The trouble starts when < is followed by something that looks like a tag, because CommonMark passes it through as raw HTML. Write <div> or put it in backticks.
Escaping differs between renderers
Escaping rules depend on which Markdown flavor reads your file. CommonMark and GitHub agree on the basics, but older and custom parsers may support only Gruber's twelve characters. The differences between those flavors are covered in CommonMark vs GitHub Flavored Markdown.
Our own tool has a limit here. The Markdown preview on OnlineViewer uses a small built-in renderer for headings, emphasis, code, links, images, quotes and lists. It is not a full CommonMark or GFM parser. Use it for a quick look, then test edge cases like escaped pipes on the platform that will publish your file. If you turn Markdown into a web page yourself, displaying Markdown in HTML walks through the options.
FAQ
Which characters can I escape in Markdown?
In CommonMark, any ASCII punctuation character can be escaped with a backslash. That covers the usual suspects: asterisk, underscore, backtick, hash, brackets, parentheses, plus, minus, dot, exclamation mark, pipe and the backslash itself.
How do I show a literal backslash in Markdown?
Type two backslashes. The first one escapes the second, so the output shows a single backslash.
Why does my backslash show up inside inline code?
Backslash escapes do not work in code spans or code blocks. Everything inside backticks is literal, so the backslash prints as typed. To put a backtick inside inline code, wrap it in a longer run of backticks instead.
How do I stop a line starting with a year from becoming a numbered list?
Escape the period after the number, as in 1986\. What a great season. The escaped dot is treated as a normal character, so no list is created.
Does escaping work in GitHub issue titles?
No. GitHub Docs note that Markdown formatting is not ignored in the title of an issue or a pull request. Backslash escapes work in comment and file bodies.