HTML Escape / Unescape: A Practical Guide
Use HTML Escape / Unescape to convert special characters to HTML entities or decode entities back into text. Choose the operation according to the context. Escaping for HTML is different from URL encoding, JSON escaping or sanitizing untrusted markup.
How to Use HTML Escape / Unescape
- Paste the text.
- Choose Escape HTML or Unescape HTML.
- Select Process.
- Inspect the output before inserting it into another context.
Entities Represent Literal Characters
Escape mode replaces characters such as ampersand, angle brackets and quotes with entity forms. This can help display markup as text rather than having the browser interpret it as an element.
Unescape mode decodes entities. Decoded output can contain active-looking markup, so do not insert it as trusted HTML merely because a tool decoded it. Context-specific escaping and sanitization are separate concerns.
Worked Example
Escaping <b>Hello</b> produces text that can be displayed as literal markup. Unescaping <b> returns angle-bracket text again.
If an already escaped ampersand is escaped again, double-encoding can occur. Track which representation you are handling.
Encode URI components: use the URL Encoder.
Create a supported anchor: use the HTML Link Generator.
Checks and Common Mistakes
- Choose the correct direction.
- Do not treat unescaping as sanitization.
- Avoid double encoding.
- Use context-specific protection for attributes, scripts and URLs.
Frequently Asked Questions
Will escaping make any HTML safe everywhere?
No. Safety depends on the insertion context and the appropriate escaping or sanitization method.
Is this the same as URL encoding?
No. They use different representations for different contexts.
Why do I see &lt;?
The text may have been escaped twice.
Related Tools for the Next Step
- URL Encoder: Encode URI components.
- HTML Link Generator: Create a supported anchor.
- JSON Validator: Check JSON syntax separately.
- Heading Extractor: Inspect supplied HTML elements.
Reference
Further reading: MDN character references.
