About HTML entities
Why HTML needs escaping
A browser reads < as the start of a tag and & as the start of a character reference. Text that contains them has to be escaped to show up as written. Five characters matter: & becomes &, < becomes <, > becomes >, " becomes " and ' becomes '.
The everyday reasons are showing code samples on a web page and, more importantly, security. If a comment, a user name or a search term is placed into a page without escaping, a value like <script> runs as code in the browser of every visitor. That is cross-site scripting (XSS), one of the most common web vulnerabilities.
Named and numeric character references
HTML defines more than two thousand named references, such as , ©, — and é. Any Unicode character can also be written by number, in decimal (é) or hex (é), and both of those give é. 😀 is the grinning face emoji.
On a page saved and served as UTF-8, you can type accents, Chinese and emoji directly. Only the five special characters need escaping. The name ' came from XML and was not part of HTML 4, which is why ' is the safer choice for a single quote and why this tool uses it.
What this tool encodes and decodes
Encode replaces exactly the five characters above. It handles & first, so nothing gets escaped twice, and leaves every other character, including accents and emoji, as it is.
Decode turns any decimal or hex numeric reference into its character, and knows all 252 named references from HTML 4 plus ': the ones you meet in practice, such as , —, ©, €, accented letters, Greek, arrows and math symbols. Rarer names added in HTML5, such as ✓, are left as written, and so is a reference without its closing semicolon. Decoding is a single pass: &lt; becomes <, so run it again for text that was encoded twice. Everything runs in your browser.
Where HTML escaping is not enough
Entity encoding protects text between tags and inside quoted attribute values. It does not make a value safe inside a <script> block or an event attribute such as onclick, because the browser decodes the entities before running the code. In an href or src, a javascript: URL still runs, so check the scheme and URL-encode each value. Always quote attribute values. Most template systems, including React, Vue, Twig and Laravel Blade, escape output by default, so escaping by hand as well makes text like & show up on the page.
Frequently asked questions
- What is the difference between and a normal space?
- is a non-breaking space (U+00A0). The browser will not wrap a line at it and will not collapse several of them into one. Its numeric form is  . This decoder understands both, and turns either into the real character.
- Do I need to escape > in HTML?
- In normal text, only < and & must be escaped, and inside an attribute value the quote character that wraps it. Escaping > as well is harmless and common, so most encoders, including this one, do it.
- Why does my page show & or < as text?
- The text was escaped twice, often once by your code and once by the template engine. The page source then holds &amp; or &lt;. Remove the manual escaping, or decode the stored text once before it is rendered.