HTML & String Escape / Unescape Online
Escape text for HTML or unescape character references in your browser, and escape strings for JavaScript and JSON: quotes, backslashes and control characters become \n, \r and \t.
How it works
- Escapes & < > " and ' for HTML text nodes. This is not a full XSS sanitizer for attributes or scripts.
HTML mode encodes & < > " and ' as HTML entities. JavaScript / JSON mode writes the content of a double-quoted string literal: backslashes and quotes are escaped, and control characters become \n, \r, \t or \uXXXX.
About HTML escaping
What is HTML escaping?
HTML escaping replaces characters that have special meaning in HTML so they render as text instead of markup. This page encodes & < > " and ' to & < > " and '.
Unescape reverses that: it decodes named references amp, lt, gt, quot, and apos, plus numeric references such as ' and '. Work happens in your browser. Escaping text nodes is not a substitute for context-aware encoding or an XSS sanitizer.
Escape and unescape in code
- JavaScript
text.replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, """) .replace(/'/g, "'")- Python
html.escape(text, quote=True) html.unescape(text)- Entities
& & < < > > " " ' '
HTML escape FAQ
- What is HTML escape?
- HTML escaping encodes characters that would otherwise be treated as markup. This page turns & < > " and ' into & < > " and ' so they display as text.
- What is HTML unescape?
- HTML unescape decodes character references back to text. Named amp, lt, gt, quot, and apos are supported, as are decimal and hexadecimal numeric references.
- Does HTML escape prevent XSS?
- No. Escaping those five characters is enough for HTML text nodes, but attributes, URLs, and scripts need context-aware encoding. This is not a sanitizer.
- How do I HTML-escape a string in code?
- In JavaScript replace & < > " and ' with their entities. In Python use html.escape(text, quote=True) and html.unescape(text).
- How do I escape a string for JSON or JavaScript?
- Switch the mode to JavaScript / JSON string and press Escape. The result is the content of a double-quoted string literal without the quotes: He said "hi" becomes He said \"hi\", and a line break becomes \n.