Skip to content
Buy me a coffee
String Escaper & Utilities

HTML Escape / Unescape

Escapes or unescapes an HTML string, replacing characters that could be wrongfully interpreted as markup with their HTML entities.

Ctrl + Enter

HTML escaping explained

Why escape HTML?

In HTML a handful of characters have a special meaning: < and > delimit tags, & starts a character reference, and quotes delimit attribute values. When one of these characters appears in content (a user's comment, a product name, a code sample…) it must be replaced by a character reference, otherwise the browser will try to interpret it as markup. Forgetting to do so is the root cause of cross-site scripting (XSS) vulnerabilities and of countless rendering glitches.

Unescaping is the reverse operation: character references (&eacute;, &#233;, &#xE9;) are turned back into the characters they represent.

Rules applied by this tool

CharacterEscaped asWhy
& (ampersand)&amp;Starts every character reference. It must always be escaped first.
< (less than)&lt;Opens a tag.
> (greater than)&gt;Closes a tag. Escaping it is optional in text but recommended.
" (double quote)&quot;Delimits attribute values.
' (single quote)&#39;Also delimits attribute values. The numeric form is used because &apos; is not defined in HTML 4.
ISO-8859-1 characters and symbols (é, ü, ©, €, →, …)Named entity such as &eacute;, &copy;, &euro;Only when the first option is checked. Uses the 252 entities defined by HTML 4 (Latin-1, Greek letters, math symbols, arrows).
Any other non-ASCII character (e.g. 日, 😀)Decimal reference &#26085;Only when the second option is checked. Useful when the page is not served as UTF-8.

The complete list of named entities, with their numbers and descriptions, is available on the HTML entities page.

Before / after

InputEscaped output
<a href="x">é & ü</a>&lt;a href=&quot;x&quot;&gt;&eacute; &amp; &uuml;&lt;/a&gt;
5 > 3 && 2 < 45 &gt; 3 &amp;&amp; 2 &lt; 4
It's "quoted"It&#39;s &quot;quoted&quot;
Price: 10 € © 2024Price: 10 &euro; &copy; 2024

Unescaping

The unescape button understands all three forms of character references: named (&nbsp;), decimal (&#160;) and hexadecimal (&#xA0;). Unknown entity names are left untouched. Note that unescaping user-supplied text and inserting the result into a page re-introduces the exact XSS risk that escaping prevents; only unescape data you intend to treat as text.

In code

// JavaScript (text nodes escape automatically)
element.textContent = untrustedString;

// PHP
echo htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');

// Java (Apache Commons Text)
StringEscapeUtils.escapeHtml4(s);

// Python
import html; html.escape(s, quote=True)