# HTML entity encoder and decoder

Escape text for HTML with named, decimal or hex entities, or turn entities such as & and &eacute; back into characters.

https://codeknife.dev/en/html-entities/

## What it does

Escapes text for HTML, and turns HTML entities back into characters. An entity writes a character by name (`&eacute;`), as a decimal number (`&#233;`) or as a hex number (`&#xE9;`).

## How to use it

1. Type or paste text, or drop a text file.
2. Pick **Encode** or **Decode**. When encoding, choose whether to escape only the characters HTML reads as markup or every non-ASCII character too, and whether to write names, decimal numbers or hex numbers.
3. Copy or download the result.

## Examples

Escaping markup:

`<p class="x">Tom & Jerry</p>` becomes `&lt;p class=&quot;x&quot;&gt;Tom &amp; Jerry&lt;/p&gt;`. With every non-ASCII character escaped, `café © €` becomes `caf&eacute; &copy; &euro;`.

## Good to know

- The characters that always need escaping in HTML text and attributes are `&`, `<`, `>`, `"` and `'`.
- The apostrophe is written `&#39;`, because HTML 4 has no name for it. Decoding also reads `&apos;`.
- Characters with no name, such as emoji, are written as numbers, one number per character.
- The table of names covers the 252 entities of HTML 4.01. A name outside it is left as typed when decoding.

## What is an HTML entity?

An entity is a way to write a character in HTML without typing it: a name such as &eacute;, or a number such as &#233; (decimal) or &#xE9; (hex). Five characters must be escaped in text and attributes because HTML reads them as markup: & < > and the two quote marks.

## Frequently asked questions

### Which characters must I escape?

Escape & and < in text, and the quote mark that surrounds an attribute value inside it. Escaping > and both quote marks everywhere is harmless and the safe default, which is what Markup only does. Escaping user input this way is the first defence against injected markup.

### Why does the apostrophe become &#39; and not a name?

HTML 4 has no named entity for the apostrophe. &apos; exists in XML and HTML5 but older software does not know it, so a number is the safe choice. Decoding accepts both.

### Does this tool send my text anywhere?

No. Everything happens in your browser. What you type is never sent to our servers.