Articles
Published · July 4, 2026

Escaping Special Characters in Markdown: A Backslash Guide

A backslash escape turns a Markdown character back into plain text — but only in some places. This guide covers the full CommonMark escapable set, why backslashes are inert inside code spans, the trailing-backslash line-break exception, and platform quirks on GitHub and Apple's own markup.

Quick answer

A backslash before a character tells Markdown to treat it as plain text instead of formatting syntax: \*not italic\* prints as *not italic* instead of turning italic. CommonMark's spec says any ASCII punctuation character can be escaped this way — not just the handful of symbols most people think of as "special."

There's one big exception: backslashes don't do anything inside a code span or fenced code block, because that text is already literal. And one special case that isn't really "escaping" at all — a backslash at the end of a line forces a hard line break.

How it actually works

The full escapable set

CommonMark's rule is broad: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ { | } ~ — every one of those can be backslash-escaped, and the escaped character loses whatever formatting meaning it would otherwise carry. In practice you'll reach for a much smaller subset most of the time: asterisk and underscore (to kill emphasis), hash mark (to stop a line from becoming a heading), and period (to stop 1.` from starting a numbered list).

John Gruber's original Markdown syntax defined a slightly narrower list of 15 characters, and explained the feature's purpose plainly: ampersands are "bedeviling for web writers" because raw HTML requires hand-encoding them, and the backslash mechanism exists so writers don't have to think about which punctuation needs protecting before they type it. If you're formatting a document meant to render consistently across CommonMark, GitHub Flavored Markdown, and older Markdown.pl-style parsers, sticking to Gruber's smaller set — \ ` ` * _ { } [ ] ( ) # + - . !` — is the safest bet. Longer reads benefit the same way clear heading structure does: predictable syntax keeps the writer's attention on the content, not the renderer's quirks.

Where backslashes don't work

Escapes are inert inside code spans and fenced code blocks. Typing ` \bold\ ` inside backticks prints the backslash and the asterisks literally — there's nothing to escape, because code content is never parsed as Markdown formatting in the first place:

This code span needs no escaping: `*just type the asterisk*`

The fix is simple: use the backslash outside of code, and skip it entirely inside code.

The trailing-backslash line break

One case looks like escaping but isn't: a backslash at the very end of a line forces a hard line break in the rendered output.

First line ends with a backslash\
This starts on a new line, same paragraph.

Functionally that's identical to ending a line with two trailing spaces. The backslash version is just easier to spot in a diff or code review — invisible trailing whitespace tends to get silently stripped by editors and linters.

When to use it (and when to skip it)

Reach for a backslash escape when:

  • You need a literal asterisk, underscore, or hash mark in running prose — \* for a literal asterisk, \# to stop a line from becoming a heading.
  • A line legitimately starts with a number and a period but isn't meant to be a numbered list — 1\. First, not a list item.
  • You're building a link or reference where a literal parenthesis or bracket would otherwise close the syntax early. Escapes still apply inside URLs, link titles, and link reference definitions, even though those look "code-like" — see inline vs. reference-style links for the full syntax.

Skip it when:

  • You're inside a code span or fenced code block — nothing there needs escaping.
  • You're writing a fenced code block's info string in an unusual way — test the specific renderer, since behavior there is inconsistent across parsers.
  • The "special" character isn't actually adjacent to formatting syntax — it's a nice day doesn't need the apostrophe escaped just because it's punctuation.

Two platform quirks are worth flagging. On GitHub, the same backslash mechanism applies everywhere in Markdown bodies, but GitHub's own docs note that formatting — and therefore escaping — is ignored entirely in issue and pull request titles, which always render as plain text. And Apple's own documentation markup, used in Swift doc comments and Xcode Playgrounds, reuses the identical convention — including escaping a leading asterisk so it isn't mistaken for a bullet point.

Frequently Asked Questions

Why doesn't a backslash escape work inside a code block?

Code spans and fenced code blocks are already rendered literally by design, so Markdown never applies its formatting rules inside them in the first place. A backslash there has nothing to escape — it just prints as a literal backslash character alongside whatever follows it.

What does a backslash at the end of a line do in Markdown?

It's the one exception to the escaping rule: a backslash at the very end of a line forces a hard line break in the rendered output, rather than escaping the character that follows. Two trailing spaces do the same thing, but a trailing backslash is more visible in a diff.

Do I need to escape characters inside a URL or link title?

Sometimes, yes — unlike code spans, URLs, link titles, and link reference definitions are parsed as normal Markdown structure, so a literal parenthesis or bracket inside a link destination can still need a backslash escape to avoid breaking the link syntax.

Is the escapable character list the same in every Markdown flavor?

Mostly, but not identically. CommonMark allows any ASCII punctuation character. The original Markdown.pl syntax defines a narrower 15-character list. For content meant to render consistently everywhere, stick to the smaller, universally-supported set.

How Carets fits in

Carets edits plain Markdown exactly as written, so a backslash-escaped character shows up in the raw text and in the preview exactly the way CommonMark defines it — no proprietary rich-text layer silently "fixing" an escaped asterisk or swallowing a trailing backslash. Syntax highlighting makes an escape sequence visually distinct from real formatting, so it's easy to confirm at a glance that \* is staying literal instead of turning italic.

For writers who keep reference-heavy documents or code-adjacent notes, having files, projects, and tags to organize everything means escape-heavy technical writing doesn't get lost in a single flat folder. Carets is native and fast on iPhone, iPad, and Mac, and your files stay plain text — no lock-in, no format drift, just Markdown that renders the way you actually typed it.

Carets is available on the App Store for iPhone, iPad, and Mac.