Guide

HTML Entities: Escape, Encode and Decode Safely

Short answer: HTML gives special meaning to <, >, & and quotes. To show them as text, write them as entities such as &lt; and &amp;. The HTML Entity Encoder & Decoder converts text to entities and decodes named and numeric entities back. Escaping user-provided text this way is a basic defence against injecting markup into a page.

What Encode changes

Encode escapes five characters: &, <, >, " and '. For example <p>Tom & Jerry's "show"</p> becomes:

&lt;p&gt;Tom &amp; Jerry&#39;s &quot;show&quot;&lt;/p&gt;

Tick Also encode non-ASCII to turn every character above U+007F into a numeric entity: café €5 <b> becomes caf&#233; &#8364;5 &lt;b&gt;, and an emoji becomes a single entity such as &#128512;.

When to encode non-ASCII

Mostly when a page cannot be served as UTF-8. With UTF-8, which is the default today, accented letters, symbols and emoji can be written directly.

Decoding

Decoding understands named entities (&copy;, &euro;), decimal (&#8364;) and hexadecimal (&#x20AC;) ones. It uses the browser's own HTML rules, so:

  • &amp;lt; decodes once, to &lt;;
  • a few legacy entities such as &copy work without the semicolon;
  • unknown names such as &unknown; are left as they are;
  • impossible numbers like &#0; or &#x110000; become the replacement character;
  • numbers 128 to 159 follow the HTML table for Windows-1252, so &#128; is the euro sign;
  • &nbsp; becomes a non-breaking space, which looks like a normal space but is a different character.

Markup in the input is never interpreted or run. Decoding returns text only.

Double escaping

If text shows &amp;lt; on a page, it was escaped twice and needs two decoding passes. The Swap button moves the output back into the input and flips the mode, which is a quick way to confirm that a round trip returns the original.

Escaping is not a complete defence

Escaping those five characters is the right way to put untrusted text between HTML tags, and it protects quoted attribute values. It is not enough inside a <script> block, a style block, an unquoted attribute or a URL. Those contexts need their own escaping, such as URL percent-encoding for links, or string escaping for JavaScript and JSON, which the String Escape & Unescape tool handles by context. For risky patterns in code, see AI-generated code insecure patterns.

How to encode and decode HTML entities with the tool

  1. Open the HTML Entity Encoder & Decoder.
  2. Choose Encode or Decode and paste your text.
  3. Tick "Also encode non-ASCII" if you need numeric entities.
  4. Copy the output. To look up a character code, use the ASCII Table; to tidy the markup, use the HTML Formatter.

Limits to know

  • It escapes five characters, and is not a full sanitiser.
  • It does not make values safe in script, style, unquoted attribute or URL contexts.
  • Everything runs in your browser.

Frequently asked questions

Which characters does Encode change? &, <, >, " and '.

How do I decode &amp;? Choose Decode.

Why do I see &amp;lt; on my page? The text was escaped twice.

Is &nbsp; a normal space? No, it is a non-breaking space.

Is my text uploaded? No.

Related tools and guides