Escaping and HTML
By the Syncfusion DevTutorials team · Last updated
Stop Markdown from changing text you meant literally. Escape marks with a backslash, find the characters that cause trouble mid-line and at the start of a line, keep angle brackets from vanishing, use HTML tags and comments safely, and test yourself with a predict-the-render quiz.
The Sum That Lost Its Stars
Asha writes a note about how refund points are counted. She types a small sum, and a type name from the code:
Two lines that changed by themselves
Points: 2*3*4 = 24
The API returns List<string> of order numbers.
Look at the Rendered tab. The 3 turned italic, and both stars are gone. In the second line, <string> has vanished. The page says "returns List of order numbers".
Nothing is broken. Markdown read the stars as emphasis marks. The browser read <string> as an HTML tag it did not know, and hid it.
In this lesson, you will learn how to tell Markdown "show this character as it is", how HTML inside Markdown behaves, and which edge cases catch people out.
In simple words: put a backslash in front of a mark to show it as a plain character. Put code and type names in backticks.
TL;DR
- A backslash
\before a Markdown mark shows the mark as text:\*,\#,\_,\[. - Stars and underscores can turn into emphasis.
#,-,+,>and1.at the start of a line can turn into headings, lists or quotes. - Anything in
<angle brackets>may be read as HTML and disappear. Put it in backticks. - Markdown allows HTML tags. Block tags like
<details>need a blank line before Markdown inside them. - An HTML comment
<!-- like this -->is hidden on the page, but people and AI agents still read it in the raw file. - GitHub removes risky tags like
<script>and<iframe>.
A Real-World Example
Think about writing a message where quotation marks have a special job.
If someone says He said "stop", you need the inner quotes to show. You cannot let them end the sentence. So you write them in a special way, so the reader knows they are part of the text.
Markdown has the same problem. Its marks are ordinary characters: *, #, _. Sometimes you mean the mark. Sometimes you mean the character. A backslash tells Markdown "this one is just a character".
What You Will Learn
In this lesson, you will learn:
- How to escape a Markdown mark with a backslash.
- Which characters cause trouble, and where.
- Why text in angle brackets disappears.
- How to use HTML tags inside Markdown, and where they break.
- What HTML comments do, and why agents still see them.
- How to predict what a tricky line will render to.
Cheat Sheet
Escapes, HTML and comments
\*Not italic\* and \# not a heading.
2023\. A year, not a list.
Press <kbd>Ctrl</kbd> + <kbd>S</kbd> to save.
H<sub>2</sub>O and 10<sup>3</sup>
<!-- This comment is hidden on the page. -->
<details>
<summary>Show the refund steps</summary>
1. Open the order
2. Approve the refund
</details>
© 2026 Order Support Ltd
Click the "Show the refund steps" line in the Rendered tab. It opens and closes. Then look at the HTML tab to see each tag.
Escaping Characters
The Backslash
To escape a character means to stop Markdown from treating it as a mark. You put a backslash \ right in front of it. The backslash itself does not appear on the page.
Marks and their escaped versions
*italic* and \*not italic\*
# A heading
\# Not a heading
- A list item
\- Not a list item
[a link](docs/refunds.md) and \[not a link\](docs/refunds.md)
Each escaped line shows its marks as plain characters.
You can escape any of these: \ ` * _ { } [ ] < > ( ) # + - . ! | ~. A backslash before a normal letter does nothing, and the backslash stays on the page.
Inside Code, You Never Escape
Inside backticks and code blocks, every character is already plain. A backslash there is just a backslash.
Code needs no escapes
Escaped in text: 2\*3\*4 = 24
In code: `2*3*4 = 24`
A Windows path: `C:\Users\asha\refunds`
For code, file paths and formulas, backticks are usually better than escapes. They show the exact text, and they look like code, which tells the reader to copy it exactly.
If you find yourself adding many backslashes to one line, use backticks instead. A line full of \* and \_ is hard to read in the raw file.
The Characters That Cause Trouble
In the Middle of a Line
Stars and underscores are the usual problem in the middle of a line. But they do not behave the same way.
Stars and underscores mid-line
2 * 3 * 4 = 24
2*3*4 = 24
my_file_name.md
_private_ setting
~about~ 5 days
Look at each line in the Rendered tab.
2 * 3 * 4is fine. A star with spaces on both sides is not a mark.2*3*4turns the3italic. Stars touching words make emphasis.my_file_name.mdis fine. Underscores inside a word are left alone._private_turns italic. Underscores at the edges of a word do make emphasis.~about~gets a line through it in GFM. One tilde on each side is strikethrough on GitHub too.
At the Start of a Line
Some characters only matter when they start a line. There, they can turn a sentence into a heading, a list or a quote.
Line starts that change meaning
#1 priority is speed.
+ 5 points for each review.
> 30 days is too long.
1. is the lowest score.
\+ 5 points for each review.
\> 30 days is too long.
#1 stays text, because there is no space after #. But + 5 became a list, > 30 became a quote, and 1. is became a numbered list. The escaped lines at the bottom stay as plain sentences.
You met this with years in the lists lesson: 2023\. stops a year from becoming a list.
Angle Brackets and HTML
Text That Disappears
Markdown lets you write HTML tags inside your text. So anything that looks like a tag is passed to the browser as a tag. If the browser does not know the tag, it shows nothing.
Where did the text go?
The API returns List<string> of order numbers.
The API returns `List<string>` of order numbers.
The API returns List<string> of order numbers.
If a < b and c > d, swap them.
The first line lost <string>. Open the HTML tab: the tag is there, but the browser hides unknown tags. The second line uses backticks, so the type name shows. The third line uses HTML entities, which you will see next.
The last line is fine. A < followed by a space is not a tag.
This is one of the most common problems in technical docs. Type names like List<T>, placeholders like <your-api-key> and email addresses written as <name> vanish from the page. Put them in backticks.
HTML Entities
An HTML entity is a short code for a character. It starts with & and ends with ;. Markdown passes entities to the page.
| You write | The page shows | Use it for |
|---|---|---|
< and > | the less-than and greater-than signs | angle brackets in normal text |
& | & | an ampersand that must not start an entity |
© | © | the copyright sign |
→ | → | an arrow |
| a space that never breaks a line | keeping "30 days" on one line |
Most of the time, you can just type the real character, such as ©. Entities are useful for characters that are hard to type.
HTML Tags You Can Use
Small inline HTML tags work in the middle of a line. A few are useful because Markdown has no mark for them.
Useful inline tags
Press <kbd>Ctrl</kbd> + <kbd>K</kbd> to search.
Water is H<sub>2</sub>O. A kilobyte is 10<sup>3</sup> bytes.
<mark>Refunds over ₹5,000</mark> need approval.
kbd shows a keyboard key. sub and sup lower and raise text. mark highlights it.
Block HTML and the Blank Line Rule
Block HTML tags, like <div> and <details>, sit on their own lines. They have one rule that surprises everyone: Markdown inside them only works if there is a blank line between the tag and the Markdown.
A collapsible section, broken and fixed
<details>
<summary>Broken: no blank lines</summary>
1. **Open** the order
2. Approve the refund
</details>
<details>
<summary>Fixed: blank lines around the Markdown</summary>
1. **Open** the order
2. Approve the refund
</details>
Open both sections in the Rendered tab. The first one shows 1. and **Open** as raw text, all on one line. The second one shows a real numbered list with bold text.
<details> makes a section the reader can open and close. <summary> is the line they click. It is useful for long examples, logs and answers to a quiz.
HTML Comments
An HTML comment is text between <!-- and -->. It is hidden on the page.
A comment the page hides
# Refund rules
<!-- TODO: add the rule for gift cards before the 2.5 release. -->
Refunds are allowed within 30 days.
The Rendered tab shows no comment. Open the HTML tab: it is still there.
Comments are useful for notes to other writers. But they are not secret. Anyone who opens the raw file sees them. An AI agent that reads the file sees them too, and may follow them as if they were instructions.
Never put passwords, keys or private notes in a comment. And in agent files like AGENTS.md, do not leave old instructions in comments. The agent may still obey them, even though the page hides them.
Tags That Get Removed
Some HTML tags are dangerous, because they can run code or load other pages. GitHub removes them. In this box, the GFM mode shows what GitHub's filter does.
Risky tags are filtered
<script>alert("hello")</script>
<iframe src="https://example.com"></iframe>
<b>Plain bold tag is fine.</b>
The script and iframe lines are shown as text, not run. Many docs sites remove even more tags, or all HTML. If your file must work everywhere, use Markdown first and HTML only when there is no Markdown way to do it.
Predict the Render
Twenty short snippets, each one an edge case from this chapter. Pick what you think each one renders to, then compare with the real render. The pass mark is 16 out of 20. Every miss links to the rule in the spec that explains it.
Where This Is Used
- API docs: type names like
List<T>in backticks, so they do not vanish. - README files:
<details>sections for long install notes or logs. - Keyboard shortcuts:
<kbd>tags in help pages. - Maths and formulas: backticks or escapes so stars do not turn into italics.
- Agent files: no hidden instructions in comments.
Common mistakes
| Symptom | Cause | Fix |
|---|---|---|
| Part of a formula turned italic | Stars touching words make emphasis | Put the formula in backticks, or write \* |
| A type name or placeholder vanished | Text in angle brackets is read as an HTML tag | Put it in backticks, or write < and > |
| A sentence became a list or a quote | It starts with +, -, > or a number and a full stop | Escape the first character with \ |
Markdown inside <details> shows as raw text | No blank line between the HTML tag and the Markdown | Add a blank line after <summary> and before </details> |
| A backslash shows on the page | It was in front of a normal letter, or inside code | Remove it; escapes only work before marks, outside code |
| An agent followed an old rule nobody can see on the page | The rule was left in an HTML comment | Delete old instructions instead of commenting them out |
A <script> or <iframe> shows as text | GitHub filters risky tags | Use a link or an image instead |
Quick Check
Exercises
What to Remember
- A backslash before a mark shows the mark as text:
\*,\#,\_,\+,\>. - Inside backticks, nothing is a mark, and nothing needs escaping.
- Stars touching words, and underscores at word edges, make emphasis. Underscores inside words are safe.
#,-,+,>and1.at the start of a line change the line's meaning.- Text in angle brackets can vanish as an unknown HTML tag. Use backticks.
- Block HTML needs blank lines around the Markdown inside it.
- HTML comments are hidden on the page, but not from people or AI agents reading the file.
Further Reading
- CommonMark: backslash escapes: the full list of characters you can escape.
- CommonMark: HTML blocks: why the blank line matters.
- GitHub Flavored Markdown: disallowed raw HTML: which tags GitHub filters.
Next: Markdown Flavors, where you render one file as CommonMark, as GitHub Flavored Markdown and on a docs site, and make it look the same in all three.