Skip to content
WebTricks

HTML entity encoder / decoder

Escape text to HTML entities or decode entities back to characters. Named, decimal and hex entities supported.

Entities
<a href="x">Tom & Jerry’s</a>

What this HTML entity tool does

Encode takes plain text and escapes the five characters that have meaning in HTML — &, <, >, " and ' — into &amp;, &lt;, &gt;, &quot; and &#39;. The result can be dropped into element content or an attribute and will display literally instead of being parsed as markup. Decode does the reverse for named entities, decimal (&#169;) and hexadecimal (&#xA9;) references. The logic is a pure string replace with no DOM involved, so it behaves the same everywhere and runs entirely in your browser.

How to use it

  1. Pick Encode or Decode.
  2. Paste into the input box. The sample <a href="x">Tom & Jerry’s</a> shows all the interesting characters at once.
  3. The output updates as you type — notice the curly apostrophe ’ in the sample is not touched, because it has no special meaning in HTML.
  4. Click Copy.

The five characters and their entities

CharacterNamedDecimalHexWhy it is dangerous
&&amp;&#38;&#x26;Starts an entity — &copy 2024 can render as © 2024
<&lt;&#60;&#x3C;Opens a tag; <script> is the classic injection
>&gt;&#62;&#x3E;Closes a tag; escaped for symmetry and safety in attributes
"&quot;&#34;&#x22;Ends a double-quoted attribute value
'&#39; (&apos; in HTML5)&#39;&#x27;Ends a single-quoted attribute value

Encoding the sample input gives:

&lt;a href=&quot;x&quot;&gt;Tom &amp; Jerry’s&lt;/a&gt;

Strictly, only & and < must be escaped in text content, and only the matching quote inside an attribute. Escaping all five everywhere costs nothing and removes the need to remember which context you are in, which is what every templating engine (React, Vue, Jinja, Handlebars {{ }}) does by default.

Common named entities the decoder knows

EntityCharacterEntityCharacter
&nbsp;non-breaking space&copy;©
&reg;®&trade;™
&hellip;…&mdash;—
&ndash;–&laquo; &raquo;« »
&euro;€&deg;°

Anything else — &eacute;, &rarr;, &hearts; — must be written numerically (&#233;, &#8594;, &#9829;) to be decoded here. In practice, modern UTF-8 pages rarely need named entities beyond the five above and &nbsp;; you can type → and ♥ directly.

Decoding gotchas

  • Double-escaped text. Content that was escaped twice (common when a CMS escapes on save and on render) shows &amp;lt; on the page. One decode pass turns it into &lt;, a second into <. The tool decodes one level per run, so paste the output back in if you need both.
  • Case matters for names. &AMP; is not a valid entity in HTML; the tool is lenient and decodes it, but browsers will not.
  • Missing semicolon. &copy 2024 is not decoded — the decoder requires the closing ;. Browsers forgive some legacy names without it, which is exactly why unescaped & in URLs (?a=1&copy=2) can corrupt your links.
  • Numeric zero (&#0;) and out-of-range code points are left as-is rather than producing invalid characters.
  • URL encoder / decoder — the other escaping you need for links: & in an href needs both percent-encoding rules and &amp;.
  • JSON formatter & validator — JSON embedded in a <script> tag needs < escaped as <, a different mechanism.
  • Case converter — normalize text before it goes into attributes or IDs.
  • Text diff — spot the difference between a stored string and its escaped copy.
  • Regex tester — test the /[&<>"']/g pattern used by most escape helpers.

FAQ

Which characters must be escaped in HTML?

Five cover every context: & (ampersand), < and > (tag delimiters), and the two quote characters " and ' for attribute values. Encode mode converts exactly these five and leaves everything else, including accented letters and emoji, untouched.

What is the difference between named, decimal and hex entities?

They are three spellings of the same thing. &copy;, &#169; and &#xA9; all produce ©. Named forms are readable but limited to a fixed list; numeric forms work for any Unicode code point. Decode mode understands all three.

Why is the apostrophe encoded as &#39; and not &apos;?

&apos; was not part of HTML 4 and older browsers (Internet Explorer 8 and earlier) did not render it. The numeric &#39; works everywhere, so it is the safe choice; the decoder still accepts &apos;.

Do I need to escape accented characters like é?

Not if your page is served as UTF-8 with a matching charset meta tag, which is standard today. Entities like &eacute; date from the era of Latin-1 pages. Encode mode therefore leaves them as literal characters.

Why was a named entity like &eacute; left untouched when decoding?

The decoder knows the common names (amp, lt, gt, quot, apos, nbsp, copy, reg, trade, hellip, mdash, ndash, laquo, raquo, euro, deg) plus every numeric form. Rare names outside that list are passed through unchanged — use the numeric equivalent such as &#233; instead.

Is escaping HTML enough to prevent XSS?

It is the right defense for text and attribute values. It is not enough inside a script block, an inline event handler, a style attribute or a URL — each of those has its own escaping rules, and the safest option is not to put untrusted data there at all.