To display a character that Markdown would otherwise treat as formatting, put a backslash (\) in front of it. For example, \*text\* shows literal asterisks instead of italic text. The backslash tells the parser to treat the next character as plain text. Escaping is only needed for special characters, and it has no effect inside code.
Escaping characters in Markdown syntax reference
| Goal | Syntax |
|---|---|
| Literal asterisk | \* |
| Literal backtick | \` |
| Literal hash | \# |
| Literal backslash | \\ |
Escaping characters in Markdown key facts
- A backslash before a special character makes that character render literally, and the backslash itself disappears.
- Only punctuation is escapable. A backslash before a letter, a digit, or a space stays visible in the output.
- To show a literal backslash, double it:
\\. - Backslash escapes do not work inside code spans, code blocks, autolinks, or raw HTML, where everything is already literal.
- CommonMark, GFM, and Pandoc let you escape any ASCII punctuation character. Original Markdown, MultiMarkdown, and Markdown Extra use a fixed list of formatting characters.
- HTML entities such as
*or*are an alternative way to display a literal character, and they work in more places than a backslash.
Decide whether to escape, quote, or use code formatting
Use a backslash when a punctuation mark would otherwise start Markdown syntax, such as \*, \#, or 1\.. Use inline code when the reader needs to see a literal command or syntax fragment. Use an HTML entity only when a character cannot be expressed safely in the destination format.
Backslash escapes do not operate inside code spans or code blocks because content there is already literal. Pipes inside tables are a special practical case: many GFM-compatible parsers require \| inside a cell. When a file targets more than one renderer, test punctuation-heavy examples rather than assuming every extension follows the CommonMark escape set.
Basic syntax
Put a backslash directly before a special character to escape it. The backslash itself does not appear in the output; the character after it is shown literally, with its formatting meaning removed.
Markdown
Use \*asterisks\* to show literal stars, not italics.
Rendered output
Use *asterisks* to show literal stars, not italics.
HTML output
<p>Use *asterisks* to show literal stars, not italics.</p>
Without the backslashes, *asterisks* would render as italic text. The escape keeps the asterisks visible and cancels the emphasis.
The list of escapable characters
Original Markdown defines a specific set of characters that a backslash can escape. CommonMark widened this to any ASCII punctuation character. The classic set covers the characters that actually carry formatting meaning.
The original Markdown escapable set is:
\ backslash
` backtick
* asterisk
_ underscore
{ } curly braces
[ ] square brackets
( ) parentheses
# hash
+ plus
- minus (hyphen)
. dot
! exclamation mark
Markdown
\\ \` \* \_ \{ \} \[ \] \( \) \# \+ \- \. \!
Rendered output
\ ` * _ { } [ ] ( ) # + - . !
HTML output
<p>\ ` * _ { } [ ] ( ) # + - . !</p>
In CommonMark, GitHub Flavored Markdown, and Pandoc, a backslash before any ASCII punctuation character is a valid escape, so the set is broader. A backslash before a letter or a digit is not an escape and stays in the output as a literal backslash.
When escaping is needed
Escape a character only when it would otherwise trigger formatting you do not want. Most punctuation is safe most of the time. The common cases are asterisks and underscores that would start emphasis, hashes at the start of a line that would start a heading, and brackets that would start a link.
Escaping emphasis markers
Markdown
The variable \_count\_ holds the total.
Rendered output
The variable _count_ holds the total.
HTML output
<p>The variable _count_ holds the total.</p>
Escaping a heading hash
A hash at the start of a line starts a heading. Escape it to show a literal hash there.
Markdown
\# This is not a heading, just text starting with a hash.
Rendered output
# This is not a heading, just text starting with a hash.
HTML output
<p># This is not a heading, just text starting with a hash.</p>
Escaping list markers and link brackets
Markdown
1\. This is not a numbered list item.
Show literal brackets: \[not a link\].
Rendered output
1. This is not a numbered list item.
Show literal brackets: [not a link].
HTML output
<p>1. This is not a numbered list item.</p>
<p>Show literal brackets: [not a link].</p>
Escaping a backslash itself
Because the backslash is the escape character, you escape a literal backslash by doubling it. A single backslash before a non-special character is left as-is in most parsers, but doubling is the reliable way to show one.
Markdown
The Windows path is C:\\Users\\Public.
Rendered output
The Windows path is C:\Users\Public.
HTML output
<p>The Windows path is C:\Users\Public.</p>
Escaping is not needed inside code
Inside inline code and code blocks, everything is already literal. A backslash there is just a backslash, and special characters keep their literal form without escaping. This is often the cleanest way to show tricky text.
Markdown
The pattern `\d+` matches one or more digits, and `*.md` is a glob.
Rendered output
The pattern \d+ matches one or more digits, and *.md is a glob.
HTML output
<p>The pattern <code>\d+</code> matches one or more digits, and <code>*.md</code> is a glob.</p>
If your text contains many special characters, wrapping it in code is usually simpler than escaping each one. To show a literal backtick inside code, use a longer run of backticks rather than a backslash, since escaping does not work in code. See code in Markdown for that technique.
Where backslash escapes do not work
Backslash escaping applies to normal text, but not everywhere. In CommonMark and the flavors that follow it, a backslash is treated as a literal character, not an escape, inside four contexts: code spans, code blocks, autolinks, and raw HTML. In all four, the content is already literal, so there is nothing to escape.
- Inside inline code and fenced or indented code blocks, characters render exactly as typed. Use a longer run of backticks to show a backtick, rather than a backslash.
- Inside an autolink such as
<https://example.com>, the URL is taken verbatim. - Inside raw HTML, the markup is passed through untouched.
This is the practical reason wrapping tricky text in code is often cleaner than escaping: code turns off Markdown parsing entirely, so no character needs a backslash.
Using HTML entities as an alternative
Where inline HTML is allowed, you can display a special character with an HTML entity instead of a backslash. Named entities such as * (asterisk) and < (less-than sign), and numeric entities such as * (asterisk) and # (hash), all produce the literal character. Entities are recognized in more places than backslash escapes, including link URLs, link titles, and fenced-code info strings, although, like escapes, they are not processed inside code spans or code blocks.
Markdown
Show an asterisk with an entity: * and *.
Rendered output
Show an asterisk with an entity: * and *.
HTML output
<p>Show an asterisk with an entity: * and *.</p>
Use a backslash for quick, readable escaping in body text, and reach for an entity when you need a character in a place a backslash escape does not reach, or when you are already writing HTML.
Escaping pipes in a table
Inside a Markdown table, an unescaped pipe (|) is read as a column separator. To show a literal pipe in a cell, escape it with a backslash (\|). This is the one escape that comes up constantly in GitHub Flavored Markdown tables.
Markdown
| Operator | Meaning |
| -------- | ---------- |
| \| | pipe |
| \|\| | logical or |
Rendered output
| Operator | Meaning |
|---|---|
| | | pipe |
| || | logical or |
See tables in Markdown for the full table syntax.
Backslash before a non-punctuation character
A backslash only escapes punctuation. Placed before a letter, a digit, or a space, the backslash is not an escape and stays in the output. One special case: in CommonMark and several other flavors, a backslash at the end of a line is a hard line break, not an escape.
Markdown
This keeps the backslash: a\b and 1\2.
Rendered output
This keeps the backslash: a\b and 1\2.
HTML output
<p>This keeps the backslash: a\b and 1\2.</p>
Flavor differences
Backslash escaping is supported across the major Markdown specifications covered here. The difference is which characters a backslash may escape: original Markdown and its descendants use a fixed list, while CommonMark and its followers allow any ASCII punctuation.
| Flavor | Backslash escaping | Notes |
|---|---|---|
| CommonMark | Yes | Any ASCII punctuation character can be escaped. A backslash before other characters is literal. Trailing backslash is a hard line break. |
| GitHub Flavored Markdown (GFM) | Yes | Follows CommonMark, so any ASCII punctuation can be escaped. |
| MultiMarkdown | Yes | Follows the original Markdown escapable set of formatting characters. |
| Markdown Extra | Yes | Follows the original Markdown escapable set. |
| Pandoc | Yes | Any ASCII punctuation character can be escaped. A backslash before a space or before a newline has special meaning. |
In practice the difference rarely matters, because the characters people actually need to escape (asterisks, underscores, backticks, brackets, hashes) appear in the escape lists of the named specifications. The broader CommonMark and Pandoc set only comes up for less common punctuation.
Other platforms (Slack, Discord, Reddit, Obsidian)
Escaping support varies in chat and note tools:
- Slack: does not use backslash escaping. To show literal formatting characters, wrap the text in code with backticks.
- Discord: supports backslash escaping for its formatting characters, such as
\*and\_, similar to standard Markdown. - Reddit: supports backslash escaping in its Markdown editor for the usual formatting characters.
- Obsidian: supports standard backslash escaping and follows CommonMark closely.
For the full comparison of how flavors differ across all elements, see Markdown flavors.
How Markdific renders it
Markdific processes backslash escapes so that an escaped special character renders as a literal character rather than as formatting. This lets you display Markdown syntax characters without triggering their formatting.
Inside inline code and code blocks, Markdific treats content literally, so backslashes and special characters there are shown as typed without needing escapes.
Try it in the Markdific online editor.
Common mistakes and gotchas
- Escaping inside code. A backslash inside inline code or a code block is literal, not an escape. Content in code is already safe.
- Escaping a non-special character. A backslash before a letter or digit is not an escape and stays in the output. Only punctuation is escapable.
- Forgetting to double a backslash. To show one literal backslash reliably, write two:
\\. - Over-escaping. Escaping punctuation that was never going to format, such as a period in mid-sentence, just clutters the source. Escape only what would misrender.
- Trailing backslash surprise. In CommonMark, a backslash at the end of a line is a hard line break, not an escaped newline. Move it if you meant a literal backslash.
- Assuming HTML entities are escapes. Backslash escaping and HTML entities like
&are different mechanisms. Escaping handles Markdown syntax; entities handle HTML characters. - Relying on the wide set everywhere. CommonMark escapes any ASCII punctuation, but older flavors only escape the classic list. Stick to the classic characters for portable escaping.
Best practices
- Escape only the characters that would actually misrender in the current context.
- Prefer wrapping tricky text in inline code over escaping many characters one by one.
- Use double backslash (
\\) when you need to show a single literal backslash. - Remember that content inside code is already literal, so no escaping is needed there.
- For maximum portability, limit escapes to the classic Markdown set of formatting characters.
- When in doubt, preview the output. A quick render shows whether an escape was necessary.
HTML equivalent
An escaped character compiles to that literal character in the HTML output. The backslash disappears, and the character it protected appears as plain text with no surrounding formatting tags.
Markdown
Show a literal \*star\* and a literal \# hash.
HTML output
<p>Show a literal *star* and a literal # hash.</p>
FAQ
How do you escape a character in Markdown?
Put a backslash directly before the character, like \* or \#. The backslash disappears in the output and the character is shown literally, with its formatting meaning removed.
Which characters can you escape in Markdown? Original Markdown escapes a fixed set: backslash, backtick, asterisk, underscore, curly braces, square brackets, parentheses, hash, plus, minus, dot, and exclamation mark. CommonMark and Pandoc allow any ASCII punctuation character.
Do you need to escape characters inside code? No. Everything inside inline code and code blocks is already literal, so backslash escapes have no effect there. To show a backtick inside code, use a longer run of backticks instead of escaping.
How do you show a literal backslash in Markdown?
Double it: write \\ to display a single backslash. A lone backslash before a non-special character is usually left as-is, but doubling is the reliable way.
Why is my backslash still showing in the output? A backslash only escapes punctuation. Before a letter, a digit, or a space it is not an escape and stays visible. Check that the character after the backslash is an escapable punctuation character.
What happens with a backslash at the end of a line? In CommonMark and several other flavors, a trailing backslash is a hard line break, not an escaped newline. If you meant a literal backslash, move it away from the line end or wrap it in code.
Is escaping the same as an HTML entity? No. Backslash escaping handles Markdown syntax characters. HTML entities like the ampersand entity handle characters that are special in HTML. They are separate mechanisms with different purposes.
What HTML does an escaped character produce? The literal character itself, with no formatting tags. The backslash is removed and the protected character appears as plain text in the output.
How do you escape a pipe in a Markdown table?
Put a backslash before it: write \| inside the cell. Without the backslash the pipe is read as a column separator, which breaks the row. This is the most common escape in GitHub Flavored Markdown tables.
How do you show a literal underscore or asterisk in Markdown?
Put a backslash in front of each one, such as \_ or \*. This stops them from starting italic or bold. Inside a word, underscores usually stay literal anyway, but escaping makes the intent explicit.
How do you escape square brackets in Markdown?
Backslash-escape both brackets, like \[text\], so they are not read as a link or reference. This is useful when you want to show literal brackets in prose.
Where do backslash escapes not work? In code spans, code blocks, autolinks, and raw HTML. In those contexts the content is already literal, so a backslash stays as a plain backslash rather than escaping the next character.
Can you use HTML entities instead of escaping?
Yes, where inline HTML is allowed. Entities like * or * display the literal character and work in some places a backslash escape does not, such as link URLs and titles. They do not work inside code spans or code blocks.
Sources and compatibility references
Use these primary references for syntax rules. Renderer behaviour can still vary by version and configuration, so preview important documents in their final destination.
Related pages
- Markdown documentation hub
- Code in Markdown
- Emphasis: bold and italic
- Links in Markdown
- Inline HTML in Markdown
- Markdown flavors compared
