About this tool
Encode &, <, >, and quotes as HTML entities, or decode entities like & and < back to characters. Useful for safely showing code snippets on web pages, blogs and templates.
Typical uses
- Show HTML code in a blog post
- Decode entities in scraped page content
- Turn user input into text that displays safely
How to use
Enter text containing special characters or HTML entities.
Encode or decode the entities, then copy or download the result.
Encoding covers &, <, > and both quote marks. This is not a complete HTML sanitizer.
“Encode” touches exactly five characters
“Encode” runs five replacements in a fixed order. & goes first, so one pass never escapes the entities it has just written:
| Character | Output | Note |
|---|---|---|
| & | & | Must be replaced first |
| < | < | Cannot start a tag any more |
| > | > | Replaced for symmetry |
| " | " | Safe inside a double-quoted attribute |
| ' | ' | Written as the numeric ', not ' |
Everything else is copied unchanged, including accented letters, ©, emoji, non-breaking spaces and backticks. Actual results:
| Input | “Encode” result |
|---|---|
| <a href="/q?a=1&b=2">Tom's</a> | <a href="/q?a=1&b=2">Tom's</a> |
| café © ™ — 😀 | café © ™ — 😀 |
| javascript:alert(1) | javascript:alert(1) |
| &lt; | &amp;lt; |
- Encoding is not idempotent. Pressing it again on text that is already escaped turns &lt; into &amp;lt;, and the page will then show “&lt;” instead of “<”. If you are not sure whether text was escaped, try “Decode” first.
- The output is fine inside element text and inside attribute values quoted with either " or ', because nothing left in it can close a tag or a quote. Spaces are not escaped, so it is not enough for an unquoted attribute value.
- Encoding does not check URL schemes: javascript:alert(1) contains none of the five characters and comes out unchanged. A user-supplied URL needs its own scheme check before it goes into href or src.
“Decode” uses the browser’s own HTML parser
“Decode” hands the input to the browser’s HTML parser as text, so the entity names and error recovery are exactly those a browser applies when it renders a page. Names are case-sensitive and unknown names are left alone:
| Input | Result | Code points | Note |
|---|---|---|---|
| <b> | <b> | U+003C U+0062 U+003E | Common entities |
| …—€ | …—€ | U+2026 U+2014 U+20AC | Ellipsis, em dash, euro sign |
| ' | ' | U+0027 | HTML5 knows ' |
| | ⍽ | U+00A0 | A non-breaking space U+00A0 (shown as ⍽), not an ordinary space |
| 	 | ⇥ | U+0009 | A tab (shown as ⇥) |
| ⪢̸ | ⪢̸ | U+2AA2 U+0338 | Some entities stand for two code points |
| © | © | U+00A9 | All-caps © is also a standard name |
| &Copy; | &Copy; | — | &Copy; is not a standard name and stays as typed |
| &foo; | &foo; | — | Unknown names stay, with no error |
| &amp; | & | — | Only one layer is removed |
Numeric references can be decimal or hexadecimal (x or X), and reach characters outside the BMP such as emoji directly. Invalid code points do not raise an error; they are replaced as the standard prescribes:
| Input | Result | Code points | Note |
|---|---|---|---|
| ' | ' | U+0027 | Decimal |
| ' | ' | U+0027 | Hexadecimal |
| ' | ' | U+0027 | Uppercase X works too |
| A | A | U+0041 | Decoded even without the semicolon |
| 😀 | 😀 | U+1F600 | Emoji in decimal |
| 😀 | 😀 | U+1F600 | Emoji in hex |
| � | � | U+FFFD | NUL becomes the replacement character U+FFFD |
| � | � | U+FFFD | A surrogate becomes U+FFFD |
| � | � | U+FFFD | Above U+10FFFF becomes U+FFFD |
| € | € | U+20AC | 0x80–0x9F are remapped by a table in the standard: 128 (0x80) gives € |
| Ÿ | Ÿ | U+0178 | 0x9F gives Ÿ |
| &#; | &#; | — | No digits: left as typed |
| &#x; | &#x; | — | No digits: left as typed |
Pitfalls: missing semicolons, URLs and line breaks
For compatibility with old pages, HTML recognises a fixed set of common names (such as ©, &, ®, ¶, × and ¬) even without a semicolon, and replaces them as soon as the beginning matches. Actual results:
| Input | Result | Code points | Note |
|---|---|---|---|
| © | © | U+00A9 | No semicolon, still © |
| &x | &x | U+0026 U+0078 | The leading & is recognised and x is left over |
| ¬it; | ¬it; | — | There is no ¬it;, so the longest legacy name ¬ is used |
| ∉ | ∉ | U+2209 | The full name ∉ wins |
| ?id=5®=cn¶=2&lang=en×=3 | ?id=5®=cn¶=2&lang=en×=3 | — | The URL parameters reg, para and times become ®, ¶ and ×; lang needs a semicolon and survives |
- Hence the last row: do not decode URLs or query strings unless they really come from HTML source with & written as &. Inside a tag attribute a browser makes an exception (it does not replace a legacy name followed by = or a letter or digit), but this tool decodes by the rules for text, so it does replace them. For percent-encoding use “URL encoding and query editor”.
- Tags in the input are neither run nor removed: <b>bold</b> stays as it is, </textarea> decodes correctly to text, and the result only appears in the read-only “Result” box.
- The parser normalises Windows CRLF line breaks to LF (␍␊ → ␊ in the table). A lone & or one followed by a space is left as it is.
Sources
Frequently asked questions
Which characters are encoded?
&, <, > and both single and double quotes.
Does this prevent XSS?
It is not a complete HTML sanitizer. Use a dedicated security library server-side for untrusted content.
Are numeric entities supported?
Yes, decoding handles named and numeric entities such as ' and '.
Suggest an improvement to this tool
Missing an option, something awkward to use, or a wrong result? Let us know.