curly{bits}

curlybits / HTML Escape

HTML Escape & Unescape

Escape text so it shows up literally in a web page, or decode HTML entities like <, & and — back into readable text. Every named entity is supported, and nothing is uploaded.

Input
Output

How to use the HTML Escape & Unescape

  1. Choose Encode to escape text, or Decode to turn entities back into characters.
  2. Paste your text or HTML on the left. The result updates as you type.
  3. When escaping, tick Also escape non-ASCII to turn characters like é, ✓ or emoji into numeric entities for systems that only accept ASCII.
  4. Click Copy, or ⇅ Use as input to run the result through again.

Why escape HTML?

Characters like < and & have special meaning in HTML. To show them on a page, for example a code sample in a blog post or user input in a comment, they must be written as entities. Otherwise the browser treats them as tags, which breaks the layout and, with user input, opens the door to cross-site scripting (XSS).

CharacterEntityWhy
&&amp;Starts every entity
<&lt;Starts a tag
>&gt;Ends a tag
"&quot;Ends an attribute value
'&#39;Ends a single-quoted attribute

Named, decimal and hex entities

The same character can be written three ways: &eacute;, &#233; and &#xE9; all mean é. The decoder understands all of them, including the full list of more than 2,000 HTML5 names. Numeric entities work everywhere, while named ones are easier to read.

Escaping in code

JavaScriptSet element.textContent instead of innerHTML, and the browser escapes for you
Pythonhtml.escape(text) / html.unescape(text)
PHPhtmlspecialchars($text, ENT_QUOTES) / html_entity_decode($text)
JavaStringEscapeUtils.escapeHtml4(text) (Apache Commons Text)
C#WebUtility.HtmlEncode(text) / HtmlDecode

Frequently asked questions

What's the difference between HTML escaping and URL encoding?

HTML escaping makes text safe inside a web page (< becomes &lt;). URL encoding makes text safe inside a web address (a space becomes %20). Use the URL encoder for links and query strings.

Why do I see &amp;amp;lt; instead of &lt;?

The text was escaped twice. Decode it, then click ⇅ Use as input and decode again. The tool warns you when the result still contains entities.

Is escaping enough to stop XSS?

It's the main defense for text placed between tags and inside quoted attributes. Text inside <script>, style blocks or unquoted attributes needs different handling, so use your framework's built-in escaping where you can.

Is my text uploaded?

No. Encoding and decoding happen in your browser and nothing is sent anywhere.

Add this HTML escape and unescape tool to your website

Free for blogs, schools and businesses. Copy the code below and paste it into your page's HTML. The tool works exactly like this one and runs in your visitors' browsers, so nothing is uploaded. Please keep the credit line so others can find it too.

Preview embed ↗