HTML entity encode / decode
Escape text for HTML (< & "), decode named, decimal and hex entities back to text, and see every character's code point. Runs in your browser.
What it does
- Escapes text for HTML: the five special characters
& < > " 'only, or every non-ASCII character as well, as named (é), decimal (é) or hex (é) references. - Decodes named, decimal and hex references following the HTML parsing rules: legacy names without a semicolon (
© 2024), invalid code points turned into U+FFFD, and references from 128 to 159 read as windows-1252 (–is an en dash). - Spots double encoding such as
&lt;and decodes all the way in one go. - Lists every non-ASCII, special or invisible character with its code point, entity name and numeric references, which helps find stray non-breaking spaces and zero-width characters.
Text, attributes and what escaping can't fix
Between tags, only & and < must be escaped. Inside an attribute value, put the value in double quotes and escape & and "; an unquoted value ends at the first space, so escaping alone doesn't protect it.
HTML escaping is not enough inside <script> or <style>, in on* event handler attributes, or for URLs in href and src, where javascript: still runs. Those contexts need their own encoding, or no untrusted input at all.
Questions
- Do I need to escape non-ASCII characters?
- Not in a page served as UTF-8, which nearly all are. Escaping them is only useful when the text passes through something that isn't UTF-8 safe, such as an old email system or a file saved in another encoding.
- Why does
&lt;show up on my page? - The text was escaped twice: once when stored and again when displayed. Decode it fully here to see the original, then fix the code so it escapes only once, at output.
- What is the difference between
'and'? - Both mean an apostrophe.
'is valid in HTML5 and XML but not in HTML 4, so'is the safer choice and the one this tool uses.
Related tools
- URL encode / decodePercent-encode and decode, and take a URL apart.
- Punycode / IDN converterConvert international domains to and from punycode; spot lookalikes.
- Base64 / Base32 / Base58Encode and decode base64, base64url, base32, Base58 and Ascii85.
- CSP evaluatorHow well does a Content-Security-Policy stop XSS?