Development

HTML Entity Encoder / Decoder

Escape text for HTML or decode named, decimal and hex entities as you type, with options for just the unsafe characters or all non-ASCII, and a searchable entity table.

HTML Entity Encoder / Decoder
Type plain text on the left to encode it, or HTML with entities on the right to decode it.
Encode
Entity style

Escapes & < > " and ', which is enough for text and attribute values in any UTF-8 page. Characters without a common name use a decimal reference, and the apostrophe is always &#39;.

10 references
Entity reference
253 common named entities. Search by name, character, description or code point, and click a value to copy it.
CharNamedDecimal

About this tool

The HTML Entity Encoder / Decoder converts text to and from HTML character references in both directions as you type. Encoding can escape only the five characters that matter in HTML (& < > " and '), which is all you need to show code or user input safely in a page or attribute, or every character outside ASCII as well, for older systems and email templates that mangle accented letters, symbols and emoji. Choose named entities such as &eacute; where one exists, or decimal (&#233;) or hex (&#xE9;) references. Decoding uses your browser's own HTML parser in an isolated document, so all 2,231 HTML5 entity names, numeric references and edge cases come out exactly as a web page would show them, and nothing you paste can run as code. A searchable reference table lists over 250 common entities, from &nbsp; and &mdash; to arrows, maths symbols and Greek letters, with one-click copying. Everything runs in your browser.

How to use the HTML Entity Encoder / Decoder

  1. Type or paste plain text in the left box to encode it, or HTML with entities in the right box to decode it.
  2. Choose whether to escape only the five unsafe characters or all non-ASCII characters too.
  3. Pick named, decimal or hex references for the encoded output.
  4. Search the reference table for a character or entity name, and click to copy it.
  5. Copy either side with its copy button.

Use it from your code

The HTML Entity Encoder / Decoder is also a REST API endpoint. Create a free API key and call it from your own scripts and apps.

# Encode
curl -X POST https://opentools.ca/api/v1/tools/html-entity-encoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation": "encode", "text": "café <b>5 €</b>", "scope": "non-ascii"}'

# Decode
curl -X POST https://opentools.ca/api/v1/tools/html-entity-encoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation": "decode", "text": "caf&eacute; &lt;b&gt;"}'

# Look up an entity
curl -X POST https://opentools.ca/api/v1/tools/html-entity-encoder \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"operation": "lookup", "query": "euro"}'

Give us your feedback

Help us improve HTML Entity Encoder / Decoder!

Frequently asked questions

Which characters do I have to escape in HTML?

Only & and < in normal text, plus the quote character that wraps an attribute value. Escaping all five of & < > " ' covers every case, which is what the default "only unsafe characters" option does. Pages saved as UTF-8 can include accented letters and emoji directly.

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

&apos; is valid in HTML5 and XML but was not part of HTML 4, and some older email clients do not recognize it. &#39; works everywhere, so the encoder uses it even when named entities are selected.

Is decoding safe for untrusted HTML?

Yes. The text is parsed as the content of a textarea inside a separate document created with DOMParser, so tags are treated as plain text, scripts never run and nothing loads. The result is shown as text, never inserted into this page as HTML.

Why do some entities without a semicolon still decode?

Browsers accept a few old names, such as &amp and &copy, without the closing semicolon for compatibility. Decoding uses the browser's parser, so it follows the same rules a web page does.

HTML Entity Encoder / Decoder screenshot