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
Escapes the five characters that can break HTML markup or an attribute. Use this for text you put in a page with UTF-8.
Type or paste text to see the result.
How to use it
- Pick Encode or Decode.
- Paste your text. The result appears as you type.
- 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 (< > & " '), 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 (é), decimal (é) or hex (é). 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. ' is valid in HTML5 and XML but not in HTML 4, so the encoder writes ' 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. < becomes &lt;, and the page shows the literal < 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 © without ;) are left as typed.
Questions
- What is the HTML entity for a space?
- A non-breaking space is (or  ). A normal space needs no entity. Use only where two words must not be split across lines, not for layout.
- What is the difference between & 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 &. 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 (& < > " ').
- Why do I see &amp; or &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.