HTML Entity Encoder and Decoder
Part of Text tools: See all Text tools.
What is HTML Encoder?
An HTML entity encoder and decoder that works as you type. Encode mode turns &, <, >, quotes and, if you choose, every non-ASCII character into named, decimal or hex entities. Decode mode turns every HTML5 named entity and numeric entity back into text, the way browsers read them, and can undo double encoding. It runs in your browser.
How to use HTML Encoder
- Choose Encode text to HTML entities or Decode HTML entities to text.
- Paste your text or HTML in the Input box. The result appears straight away.
- When encoding, choose which characters to encode, the entity style (named, decimal or hex) and how the apostrophe is written.
- When decoding text that was escaped twice, tick Decode repeatedly.
- Copy the result, download it as a .txt file, or switch mode to check that it converts back.
Why use this tool?
Raw &, < and quotes break HTML or let markup through, and text from feeds, APIs and old databases often arrives full of & and '. This tool shows exactly what it changed, warns you about double encoding and unknown entities, handles emoji as single entities, and never uploads your text.
FAQ
- Which characters does it encode?
- By default & < > " and the apostrophe, which is enough for text between tags and inside quoted attribute values. You can choose only & < > for text between tags, add every non-ASCII character, or encode everything except letters, digits and spaces.
- Can I choose named, decimal or hex entities?
- Yes. Named uses names such as é and © where one exists and hex for the rest. Decimal gives é and hex gives é. Browsers read all three the same way.
- Does the decoder know entities like and …?
- Yes. It recognises every named character reference in the HTML standard and numeric ones in decimal or hex. Numbers 128 to 159 are read as Windows-1252 characters, as browsers do. Unknown names are left as they are and listed.
- How do I fix text that shows &amp; or &lt;?
- The text was encoded twice. Use Decode mode and tick Decode repeatedly. The tool keeps decoding, up to ten passes, until no entities are left.
- How are emoji encoded?
- As one numeric entity for the whole character, for example 😀 or 😀, not as two broken surrogate halves.
- Does HTML encoding stop XSS?
- Encoding & < > and quotes makes text safe between tags and inside quoted attributes. It is not enough inside script or style blocks, unquoted attributes or URLs, which need their own escaping from your framework.
- Is my text uploaded?
- No. Encoding and decoding happen in your browser. Your text is not sent to our server, stored or logged.
What this HTML entity tool does
This page converts text to HTML entities and back again. In Encode mode, characters that have a special meaning in HTML are replaced with entities, so a browser shows them as text instead of reading them as markup: the ampersand becomes &, the less-than sign becomes <, the greater-than sign becomes >, the double quote becomes " and the apostrophe becomes '. In Decode mode it does the opposite and turns entities such as &, , é, ’ and 😀 back into the characters they stand for.
The result updates as you type, so there is no button to press. Under the result, a short summary tells you what happened: how many characters were encoded, how many entities were decoded, whether any entity was missing its closing semicolon, whether the text looked like it had been encoded twice, and which entity names were not recognised and were left alone.
How to encode or decode HTML entities
- Choose the mode: Encode text to HTML entities, or Decode HTML entities to text.
- Paste your text or HTML into the Input box. The result appears straight away.
- When encoding, pick which characters to encode, the entity style (named, decimal or hex) and how the apostrophe is written. Tick Do not encode existing entities if your text already contains some, and Add a line break tag at each line break if you want the lines to stay separate on a web page.
- When decoding text that has been escaped more than once, tick Decode repeatedly.
- Copy the result, download it as a .txt file, or press Use result as input and switch mode to check that it converts back.
Which characters should you encode?
There are four choices, because the right answer depends on where the text is going.
- & < > " and the apostrophe (the default). These five are enough to make text safe both between tags and inside a quoted attribute value such as title="..." or alt="...". If you are not sure, use this.
- Only & < >. Between tags, quotes are harmless, so this keeps the text a little easier to read. Do not use it for attribute values.
- The five plus every non-ASCII character. Accented letters, curly quotes, dashes, currency signs, symbols and emoji are written as entities too, so the result is plain ASCII. This helps when a file will pass through a system that may damage UTF-8, such as an old email template, a CMS field or a database with the wrong character set.
- Everything except letters, digits and spaces. Punctuation is encoded as well. This is rarely needed for web pages, but it is useful for testing a parser or for hiding text from a naive filter.
Named, decimal and hex entities
The same character can be written three ways. The letter e with an acute accent can be é (named), é (decimal) or é (hexadecimal). Browsers treat them the same. Named entities are easiest for people to read. Numeric ones work for every Unicode character, including emoji that have no name, and they are also understood by XML, which only knows five named entities.
With the Named setting the tool uses the familiar HTML 4 names (such as ©, £, –, …, → and the Greek letters) and falls back to hex for anything else. Emoji and other characters outside the Basic Multilingual Plane are written as one entity for the whole code point, for example 😀, not as two broken halves. That is a common bug in encoders that work on UTF-16 units.
How decoding works
The decoder recognises all 2,231 named character references in the HTML standard, from & to rare ones such as ⫌ and 𝔗. Numeric references are handled the way browsers handle them. �, numbers above the Unicode range and surrogate code points become the replacement character, and the numbers 128 to 159, which old Windows software often produced, are read as the Windows-1252 characters they were meant to be. So – becomes an en dash and ’ becomes a right single quote.
Some entities work without their closing semicolon for historical reasons, for example & or © followed by a year. The tool decodes these the way a browser does in normal page text and tells you how many it found, because a missing semicolon is often a sign of a typing mistake. An entity it does not know, such as a made-up &foo;, is left exactly as it was and listed in the summary.
Fixing double-encoded text
Text that has been escaped twice shows entities on the page instead of characters: you see &amp; or &lt;b&gt; where you expected an ampersand or a bold tag. It happens when a template escapes data that was already escaped, or when a feed or API encodes text before a CMS encodes it again. Paste the text in Decode mode. If the result still contains entities, the summary says so. Tick Decode repeatedly and the tool keeps decoding, up to ten passes, until no entities are left, and it tells you how many passes it needed.
When you encode, the reverse problem can happen. If your input already contains entities and you encode it again, & turns into &amp;. The tool warns you when this happens. Tick Do not encode existing entities to leave anything that already looks like an entity untouched while still encoding loose ampersands and angle brackets.
Common uses
- Showing HTML, XML or code examples on a blog or in documentation so the tags appear as text.
- Putting text that contains quotes into an attribute such as alt, title or a data attribute.
- Cleaning text copied from an RSS feed, a scraped page, a JSON API or a CSV export that is full of &, ' and .
- Converting accented names and symbols to ASCII-safe entities for an HTML email or an old system.
- Checking what an entity you found in source code stands for, such as ​ (a zero-width space) or ­ (a soft hyphen).
What this tool does not do
Encoding is not a complete defence against cross-site scripting. Encoding the five special characters makes text safe between tags and inside quoted attribute values, but it does not make text safe inside a script block, a style block, an unquoted attribute, or a URL such as an href or src value. Those places need their own escaping, for example URL encoding for query strings, and your framework or template engine should do it for you automatically. Use this tool to prepare and inspect text, not as a replacement for escaping in your code.
It also does not convert the text in other ways. It does not remove HTML tags, format or minify HTML, or translate URL encoding such as %20; use the URL encoder for that. Decoded text keeps any tags it contains as plain text in the result box. Nothing is run or shown as a web page.
Privacy
All encoding and decoding happens in your browser with JavaScript. The text you paste is not uploaded to our server, saved or logged, so it is fine to use with private data such as customer messages or internal code. Inputs up to five million characters are supported.
Related tools
Use the URL encoder for query strings and links, Base64 for binary data in text, the text to binary converter to see the bytes behind each character, and Remove Extra Spaces to clean up non-breaking and zero-width spaces after decoding.
Also try
Related tools that work well with this one: