HTML Escape and Unescape

Show code or user text on a web page without the browser treating it as HTML. Escaping replaces the characters that have special meaning in HTML with character references, such as &lt; for < and &amp; for &. Unescaping does the reverse, turning references like &eacute;, &copy; and &#128578; back into the characters they stand for. Everything runs in your browser.

Inputs

Result

Escaped HTML
&lt;p class=&quot;note&quot;&gt;Fish &amp; chips for 2 &gt; 1&lt;/p&gt;
Characters before
42
Characters after
71

How it is calculated

  1. Escaped HTML: start from the text or code to escape, then replace & < > " and ' with HTML character references
  2. Characters before: start from the text or code to escape, then convert Windows and old Mac line endings to standard line breaks, then count characters as you see them, including spaces
  3. Characters after: start from the escaped html, then convert Windows and old Mac line endings to standard line breaks, then count characters as you see them, including spaces

Resources for your next step

Helpful downloads

View all developer & web downloads
Store coming soon

We are preparing practical spreadsheets, planners, and guides. Explore the store page for what is next.

Which characters are escaped

Three characters always change: & becomes &amp;, < becomes &lt; and > becomes &gt;. The ampersand starts every character reference and the angle brackets start tags, so leaving them in place can break the page or let text run as markup. With the quote option on, " becomes &quot; and ' becomes &#39;, which you need when the text goes inside an attribute value such as title="...".

In the example, <p class="note">Fish & chips for 2 > 1</p> becomes &lt;p class=&quot;note&quot;&gt;Fish &amp; chips for 2 &gt; 1&lt;/p&gt;, which a browser displays exactly as typed instead of drawing a paragraph.

What unescaping understands

Numeric references are decoded in both forms: decimal, such as &#169;, and hexadecimal, such as &#xA9;. Both give ©. A reference to a value that cannot be a character, such as &#0; or a number past the end of Unicode, becomes the replacement character �, as browsers do.

Named references are decoded for all 252 names defined in HTML 4 plus &apos;: the Latin-1 accented letters such as &eacute; and &Uuml;, symbols such as &copy; &reg; &trade; &euro; and &deg;, Greek letters, math signs, arrows and typographic punctuation such as &mdash; and &hellip;. The current HTML standard defines over 2,000 names; a rarer one is left exactly as written, so nothing is silently lost. A reference must end with a semicolon to be decoded.

Escaping is one part of web security

Escaping text before inserting it into HTML is the main defense against cross-site scripting, where someone types markup or script into a form so it runs for other visitors. This tool is handy for preparing snippets, documentation and email templates by hand.

In an application, let your template engine or framework escape output automatically for each context. Text going into a URL, a script block or CSS needs different rules; for web addresses, use percent-encoding instead.

Frequently asked questions

What is the difference between an ampersand and its escaped form?

& is the character itself; &amp; is how you write it in HTML so the browser shows an ampersand instead of starting a character reference.

Do I need to escape quote marks?

Only inside attribute values. In ordinary page text, quotes are safe, so you can turn the option off to keep the result shorter and easier to read.

Which named references can it unescape?

All 252 names from HTML 4 plus &apos;, which covers accented letters (&eacute;, &ntilde;), currency and other symbols, Greek letters, math signs, arrows and curly quotes. Numeric references such as &#9731; work for every character.

Why did a reference without a semicolon stay the same?

This tool decodes only references that end with a semicolon, which is what the HTML standard requires for new documents. For example, &copy without a semicolon is left as written. Add the semicolon to decode it.

Does escaping make my site safe from XSS?

It is the key step for text placed in HTML content, but each context (attributes, URLs, scripts, styles) needs its own handling. Use your framework's automatic escaping in real applications.

Will unescaping run any code?

No. The tool only replaces references with characters and shows the result as plain text. Nothing is rendered or executed.

Sources

Text is processed in your browser and never sent anywhere. Check escaped output in its real context before publishing.

All developer & web tools