How to Escape Characters in Markdown

To display a Markdown special character literally, put a backslash directly before it: \*not italic\* renders the asterisks as plain text. Backslash escapes apply to ASCII punctuation only — and never inside code blocks, where every character is already literal.

Platform Support

GitHubsupportedGitLabsupportedObsidiansupportedDiscordsupportedSlacksupportedNotionsupported

CommonMark lets you backslash-escape any ASCII punctuation character: \ ` * _ { } [ ] ( ) # + - . ! | < > and the rest. A backslash before anything else — a letter, a digit, a space — is just a literal backslash, so \n does not become a newline and \w stays exactly as typed. In practice only a handful of escapes matter day to day: asterisks and underscores that would start emphasis, a hash at the start of a line that would become a heading, square brackets that would open a link, and a number followed by a period at the start of a line — 1999\. prevents the year from kicking off an ordered list that renders as "1." Position matters for most of these: a hash in the middle of a sentence needs no escape at all, because it only means "heading" at the start of a line.

The escape you cannot avoid is the pipe in tables. Any literal | inside a cell splits that cell in two, so documenting a shell pipeline like grep foo | sort silently breaks the column layout. Write it as \| instead. GFM extends the escape into code spans within table cells — `a \| b` works there, even though backslashes are normally literal inside code — and the HTML entity &#124; is the fallback for renderers that do not honor the backslash form.

Literal asterisks come up constantly in technical writing: glob patterns like *.md, wildcard arguments like *args, and bullet characters in quoted text all start emphasis spans that swallow the asterisk and italicize whatever follows until the parser finds a mate. Escaping fixes it (\*.md), but inline code is usually the better tool — `*.md` needs no escaping at all, signals "this is a literal token" to the reader, and protects every character inside, including underscores in names like _private or MAX_VALUE_ that would otherwise trigger emphasis at word boundaries.

Backticks have their own escape story. Outside code, \` produces a literal backtick like any other punctuation escape. But to show a backtick inside inline code, the backslash does nothing — use a longer delimiter instead: double backticks with a space, `` `code` ``, display the inner backticks literally. That points at the rule people break most: never escape inside code blocks or code spans. Within ``` fences and `spans`, backslashes are ordinary characters, so \* renders as a visible backslash followed by an asterisk. If your output shows stray backslashes, check whether the escaped text accidentally sits inside code formatting.

Examples

Escaping Characters
Markdown
\*Not italic\*
\# Not a heading
Output

*Not italic*
# Not a heading

Escape special characters using backslash.

Escaped pipe in a table cell
Markdown
| Pattern | Meaning |
|---|---|
| a \| b | a or b |
Output
Pattern Meaning
a | b a or b

A raw | inside a cell starts a new column — escape it with a backslash.

Literal asterisks in a glob pattern
Markdown
Delete the build artifacts: \*.log and \*.tmp
Output

Delete the build artifacts: *.log and *.tmp

Unescaped, the asterisks would open emphasis spans and vanish from the output.

Preventing an accidental ordered list
Markdown
1999\. What a year that was.
Output

1999. What a year that was.

A number-period at the start of a line begins an ordered list — escape the period to keep prose as prose.

Common Mistakes

Wrong
A code block containing \*escaped\* asterisks
Right
Code blocks are already literal: *no escaping needed*

Inside code spans and fenced blocks every character is literal — backslashes render as visible backslashes instead of escaping anything.

Wrong
| matches a | b |
Right
| matches a \| b |

The unescaped pipe splits the cell into two columns. Backslash-escape literal pipes inside tables, or use the &#124; entity.

Wrong
\n to force a new line
Right
End the line with two spaces or use <br>

Backslash escapes only apply to punctuation. \n is not a newline in Markdown — it renders as a literal backslash and the letter n.

Platform Notes

GitHub

Full CommonMark escaping for all ASCII punctuation. In tables, \| works even inside code spans within cells — a GFM-specific extension of the rule.

Discord

Backslash escapes work for Discord's own markers: \*text\*, \_text\_, and \~\~text\~\~ all render the characters literally in messages.

Slack

No backslash escaping — the backslash itself shows up in the message. Wrap formatting characters in `inline code` to neutralize them instead.

Obsidian

Standard escapes work, and you can also escape wikilink brackets (\[\[not a link\]\]) to stop double brackets from creating internal links.

Frequently Asked Questions

How do I show a literal asterisk in Markdown?

Escape it with a backslash (\*) or wrap the text in inline code (`*.md`). Inside code, every character is literal and no escaping is needed.

Which characters can be escaped in Markdown?

Any ASCII punctuation character, per CommonMark: \ ` * _ { } [ ] ( ) # + - . ! | < > and others. A backslash before a letter or digit is treated as a literal backslash.

How do I put a pipe character inside a table?

Escape it as \|. In GFM this works even inside code spans within cells. If your renderer ignores the backslash, use the HTML entity &#124; instead.

Why are backslashes showing up in my rendered output?

The escaped text is probably inside a code span or code block, where backslashes are literal — or the platform (like Slack) does not support backslash escaping at all.

Do I need to escape characters inside code blocks?

No, never. Everything between backticks or inside a fenced block is already literal. Escaping there adds visible backslashes to your output.

Related Syntax

Related Tools