# HTML Entity Encoder and Decoder

> Escape text for HTML as named, decimal or hex references, or turn entities back into characters, with double-escaped text decoded round by round.

- Page: https://codethatmoves.com/tools/dev/html-entity-encoder/
- Site: Code That Moves
- Category: Developer tools
- Free, runs in the browser, nothing is uploaded
- Last checked: 2026-11-14

## What it does

- Encode only & < > " ', everything outside ASCII, or every character except letters and digits
- Write references as named (&eacute;), decimal (&#233;) or hex (&#xE9;)
- Emoji and other characters outside the Basic Multilingual Plane become one reference, not two broken surrogates
- Decodes every named reference in the HTML standard, plus decimal and hex references
- Numeric references to 0x80 to 0x9F are read as Windows-1252, the way browsers read them
- Spots double escaping such as &amp;lt; and lists each decoding round
- Swap button to send the result back the other way; the text is kept in the page address for sharing

## How to use it

1. Pick Encode or Decode.
2. Paste your text. The result appears as you type.
3. When encoding, choose which characters to escape and whether to write them as named, decimal or hex references, then copy the result.

## What it checks and why

Five characters have a job in HTML: < and > open and close tags, & starts a character reference, and " and ' end attribute values. Inside text or an attribute they must be written as references (&lt; &gt; &amp; &quot; &#39;), or the browser reads them as markup. That is also the core of preventing HTML injection when you put user text into a page.

Everything else can be written as plain UTF-8 on a page that declares UTF-8, which is every modern page. Encoding non-ASCII characters as references is still useful for email templates, XML feeds, old CMS fields and anything that may be read with the wrong character set.

A reference can be named (&eacute;), decimal (&#233;) or hex (&#xE9;). All three give the same character. Named references are easier to read, but only some characters have a name; numeric ones work for any Unicode character. &apos; is valid in HTML5 and XML but not in HTML 4, so the encoder writes &#39; for the apostrophe.

Double escaping happens when text that is already escaped is escaped again, for example by a template engine and then a CMS. &lt; becomes &amp;lt;, and the page shows the literal &lt; instead of <. In Decode mode the tool shows each round until the text stops changing.

## Specs and sources

- [HTML Standard: character references](https://html.spec.whatwg.org/multipage/syntax.html#character-references)
- [HTML Standard: named character references list](https://html.spec.whatwg.org/multipage/named-characters.html)
- [OWASP: Cross Site Scripting Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html)

## Limits

- Escaping for HTML text and attributes is not enough inside <script>, inline event handlers, style blocks or URLs; those contexts need their own encoding.
- The encoder writes names for the common set (Latin-1, punctuation, arrows, math, basic Greek) and a numeric reference for the rest. The decoder reads every name in the standard.
- Named references without the closing semicolon (a legacy &copy without ;) are left as typed.

## Questions

### What is the HTML entity for a space?

A non-breaking space is &nbsp; (or &#160;). A normal space needs no entity. Use &nbsp; only where two words must not be split across lines, not for layout.

### What is the difference between &amp; and &?

& starts a character reference in HTML. To show a literal ampersand, or to use one inside an attribute such as a URL with several query parameters, write &amp;. Browsers forgive many bare ampersands, but validators flag them and some cases break.

### Should I use named or numeric entities?

Both give the same character. Named ones are easier to read in source; numeric ones work for every Unicode character and in XML, which only knows five names (&amp; &lt; &gt; &quot; &apos;).

### Why do I see &amp;amp; or &amp;lt; on my page?

The text was escaped twice. Paste it in Decode mode: the tool shows each round, and the last one is the original text. Then fix the step that escapes it a second time.

### How do I escape HTML in JavaScript?

Set text with element.textContent instead of innerHTML and the browser escapes it for you. When you build HTML strings, replace & first, then < > " and '.

### Is my text sent anywhere?

No. Encoding and decoding run in your browser. Short text is kept only in the page link's hash, which browsers never send to a server.
