Skip to content
Developer tools

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.

Last checked

Text or HTML to encode

Characters to encode
Write as

Escapes the five characters that can break HTML markup or an attribute. Use this for text you put in a page with UTF-8.

Encoded

The result appears here as you type.

Type or paste text to see the result.

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

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.