HTML entity encoder

Encode special characters as HTML entities or decode them.

  • Runs locally
  • Free

Use the tool

Your files are processed in your browser and are not uploaded to a server.

About this tool

Encode &, <, >, and quotes as HTML entities, or decode entities like &amp; and &lt; 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

  1. Enter text containing special characters or HTML entities.

  2. Encode or decode the entities, then copy or download the result.

Good to know

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:

CharacterOutputNote
&&amp;Must be replaced first
<&lt;Cannot start a tag any more
>&gt;Replaced for symmetry
"&quot;Safe inside a double-quoted attribute
'&#39;Written as the numeric &#39;, not &apos;

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>&lt;a href=&quot;/q?a=1&amp;b=2&quot;&gt;Tom&#39;s&lt;/a&gt;
café © ™ — 😀café © ™ — 😀
javascript:alert(1)javascript:alert(1)
&amp;lt;&amp;amp;lt;
  • Encoding is not idempotent. Pressing it again on text that is already escaped turns &amp;lt; into &amp;amp;lt;, and the page will then show “&amp;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:

InputResultCode pointsNote
&lt;b&gt;<b>U+003C U+0062 U+003ECommon entities
&hellip;&mdash;&euro;…—€U+2026 U+2014 U+20ACEllipsis, em dash, euro sign
&apos;'U+0027HTML5 knows &apos;
&nbsp;⍽U+00A0A non-breaking space U+00A0 (shown as ⍽), not an ordinary space
&Tab;⇥U+0009A tab (shown as ⇥)
&NotNestedGreaterGreater;⪢̸U+2AA2 U+0338Some entities stand for two code points
&COPY;©U+00A9All-caps &COPY; 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;amp;&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:

InputResultCode pointsNote
&#39;'U+0027Decimal
&#x27;'U+0027Hexadecimal
&#X27;'U+0027Uppercase X works too
&#65AU+0041Decoded even without the semicolon
&#128512;😀U+1F600Emoji in decimal
&#x1F600;😀U+1F600Emoji in hex
&#0;�U+FFFDNUL becomes the replacement character U+FFFD
&#xD800;�U+FFFDA surrogate becomes U+FFFD
&#x110000;�U+FFFDAbove U+10FFFF becomes U+FFFD
&#128;€U+20AC0x80–0x9F are remapped by a table in the standard: 128 (0x80) gives €
&#x9F;ŸU+01780x9F 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 &copy, &amp, &reg, &para, &times and &not) even without a semicolon, and replaces them as soon as the beginning matches. Actual results:

InputResultCode pointsNote
&copy©U+00A9No semicolon, still ©
&ampx&xU+0026 U+0078The leading &amp is recognised and x is left over
&notit;¬it;—There is no &notit;, so the longest legacy name &not is used
&notin;∉U+2209The full name &notin; wins
?id=5&reg=cn&para=2&lang=en&times=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 &amp;. 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, &lt;/textarea&gt; 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 &#39; and &#x27;.