HE
HTML Entity Encode & Decode
Convert text to HTML entities and back — escape or unescape angle brackets, ampersands, quotes, and more for safe HTML embedding.
More Encoding & Crypto Tools
How to Use HTML Entity Encode & Decode
Paste text into the input box, press Encode to escape HTML special characters into their entity equivalents (<, >, &, ", '), or paste HTML with entities and press Decode to see the original text. Non-ASCII characters can optionally be encoded as numeric entities too. A Copy button grabs the result.
About HTML Entity Encode & Decode
HTML entities are how you safely include characters in an HTML document that would otherwise be interpreted as markup. If you want to display the literal text <script>alert(1)</script> on a web page — say, in a tutorial about cross-site scripting — you cannot write it directly into the HTML; the browser would try to execute it as a script tag. Instead, you replace the angle brackets, ampersands, and quotes with their entity equivalents: <script>alert('XSS')</script>. The browser renders the entities as the original characters visually, but never interprets them as code. This is one of the most fundamental web security concepts, and it is relevant far beyond security: every template engine, every blogging platform, and every content management system encodes user-submitted text this way before rendering it, to prevent both intentional attacks and accidental page breakage.\n\nThere are three kinds of HTML entities. Named entities use a mnemonic name, like & for &, < for <, > for >, " for a double quote, and for a non-breaking space — there are over 2,000 of these defined in the HTML specification, covering Latin letters with diacritics, Greek letters, mathematical symbols, arrows, and more. Numeric decimal entities use the character's Unicode code point in decimal: © for the copyright sign. Numeric hexadecimal entities use the code point in hex: © for the same copyright sign. All three forms are equivalent for characters that have a named entity. The tool uses named entities where they exist (for the five core XML/HTML characters plus commonly used ones) and falls back to numeric hex entities for everything else.\n\nWhy would you need this tool? There are a few common scenarios. You are writing a blog post or documentation that includes HTML code snippets — you need to entity-encode the angle brackets and ampersands so they display correctly in the page instead of being interpreted as HTML. You are working with a legacy system or email template that requires pure ASCII and you need to convert accented characters to their entity equivalents. You received a piece of text that contains HTML entities (é, ©, →) and you want to see the actual characters they represent. Or you are debugging why some text on your page is not rendering correctly — decoding the entities lets you see the raw string that the browser received before it applied any parsing.
Details & Tips
The five XML/HTML core entities (mandatory in every XML parser and HTML renderer) are: & for &, < for <, > for >, " for a double quote, and ' for a single quote. Among these, < and & are the most critical — forgetting to encode a < in user-submitted content is how cross-site scripting (XSS) vulnerabilities happen. An unencoded & in an HTML attribute value or URL query string can break the parser in subtler ways, causing the page to render incorrectly or the attribute to be truncated.\n\nCharacter reference syntax in detail: a decimal numeric reference starts with &# and ends with ;, with the code point in base-10 between them: A is A. A hex numeric reference starts with &#x or &#X: A is also A. A named reference uses the entity name: <. All are terminated by the semicolon, though in practice browsers are lenient and will parse an entity without a semicolon if the next character cannot be part of the name — this tool always includes the semicolon for correctness and portability.\n\nNon-ASCII encoding option: when enabled, characters above U+007F are converted to numeric hex entities. For example, café becomes café, and Japanese greetings become a sequence of hex entities. This is useful when you are targeting a legacy encoding (like ISO-8859-1 for older email clients) or when you want to guarantee that the HTML file itself can be saved and transmitted in pure ASCII. In modern practice, UTF-8 is almost universally supported, and encoding non-ASCII characters as entities adds considerable bulk — a CJK character as a numeric entity takes 7-10 bytes instead of the 3-4 bytes of its UTF-8 representation — so the option defaults to off.\n\nDecoding robustness: the decode function handles edge cases that naive regex replacements miss. Malformed entities like ¬anentity; are left as literal text rather than throwing an error or being silently dropped. Unfinished entities like & without the semicolon are also left alone. This prevents silent data corruption when decoding text that was not properly entity-encoded in the first place.
Frequently Asked Questions
Which characters are encoded by default?
The five core XML/HTML characters: & becomes &amp;, < becomes &lt;, > becomes &gt;, a double quote becomes &quot;, and a single quote becomes &#39;. With "encode non-ASCII" enabled, all characters above code point 127 are also encoded as numeric hex entities.
Why should I entity-encode user input before displaying it on a web page?
To prevent cross-site scripting (XSS). If a user types <script>alert(1)</script> as their name and your page renders it without encoding, the browser executes the script. Entity-encoding turns it into harmless display text.
What is the difference between named and numeric entities?
Named entities use a memorable name (&lt; for <). Numeric entities use the Unicode code point in decimal (&#60;) or hex (&#x3C;). They produce identical output; named entities are easier to read in source code.
Does this tool encode all 2,000+ HTML named entities?
On the decode side, yes — all standard named entities (including &eacute;, &copy;, &rarr;, etc.) are recognised. On the encode side, only the core five are used by default to keep output compact. Non-ASCII encoding uses numeric hex entities.
What happens if I encode text that is already entity-encoded?
The & in existing entities gets encoded to &amp; — this is double-encoding. For example, &lt; becomes &amp;lt;, which renders as the literal text "<" instead of "<". Always decode first if you suspect the text is already encoded.
Is my text sent to a server?
No. All encoding and decoding runs in your browser using JavaScript — nothing you paste is transmitted, logged, or stored anywhere.
Can I use this to sanitize HTML input?
Entity encoding prevents markup interpretation but it is not a complete sanitization solution. It should be combined with a proper HTML sanitizer (stripping dangerous tags and attributes) if you need to allow some HTML but block others.
Why would I encode non-ASCII characters like emoji or accented letters?
Mostly for compatibility with legacy systems that do not support UTF-8, or for embedding Unicode text in ASCII-only formats like some email transports. In modern web development, UTF-8 is standard and non-ASCII encoding is rarely needed.
Does this tool handle HTML-encoded URLs (like &amp; in query strings)?
Yes. The decode step converts entities back to their literal characters whether they appear in normal text or inside a URL string. If you have a URL with &amp; separators, decoding replaces them with &.
What about mathematical entities like &sum; or &int;?
These are decoded correctly to their Unicode characters (summation sign and integral sign). On the encode side they are handled with numeric hex entities. The full range of MathML and HTML5 named entities is supported on decode.
Part of These Collections
Also Available As
html entity encoder, html entity decoder, html escape, html unescape, html encode online, html decode online, html entities, xss prevention
Found a Problem?
Let us know if something with HTML Entity Encode & Decode isn't working as expected.
Something went wrong. Please try again.
Thanks — we'll take a look.