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
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 | 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
\*Not italic\*
\# Not a heading*Not italic*
# Not a heading
Escape special characters using backslash.
| Pattern | Meaning |
|---|---|
| a \| b | a or b || Pattern | Meaning |
|---|---|
| a | b | a or b |
A raw | inside a cell starts a new column — escape it with a backslash.
Delete the build artifacts: \*.log and \*.tmpDelete the build artifacts: *.log and *.tmp
Unescaped, the asterisks would open emphasis spans and vanish from the output.
1999\. What a year that was.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
A code block containing \*escaped\* asterisksCode 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.
| matches a | b || matches a \| b |The unescaped pipe splits the cell into two columns. Backslash-escape literal pipes inside tables, or use the | entity.
\n to force a new lineEnd 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 | 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
Bold
Learn how to make text bold in Markdown using double asterisks or underscores.
Tables
Learn how to create tables in Markdown with pipes and dashes, align columns with colons, escape pipes inside cells, and work around missing features like merged cells.
Code Blocks
Learn Markdown code formatting: inline code with backticks, fenced code blocks with syntax highlighting, nesting backticks, and indented code blocks.
Related Tools
Markdown Cheat Sheet
Complete Markdown syntax reference with interactive examples
Online Markdown Editor
Write Markdown with a formatting toolbar, local autosave, callouts, math, diagrams, file open, and live preview
Markdown Formatter
Beautify Markdown drafts with table alignment, spacing cleanup, and list marker normalization