HTML Entity Encoder / Decoder

Escape & < > " ' as HTML entities so text displays safely inside HTML, or decode named and numeric entities back to plain text.

Copied
Input0 B
Output0 B

What the HTML entity encoder and decoder do

Encode replaces the five characters that have a special meaning in HTML — &, <, >, " and ' — with character references, so the text displays literally instead of being read as markup. Decode does the reverse for every reference a browser understands: named ones such as &copy;, decimal ones such as &#169; and hexadecimal ones such as &#xA9;.

An HTML entity, properly called a character reference, starts with & and usually ends with ;. The HTML Standard defines 2,231 named references; 106 of those are legacy spellings without the final semicolon, kept for old pages. Numeric references can name any Unicode code point. XML, by contrast, predefines only five names: amp, lt, gt, quot and apos.

How to use it

  1. Type or paste text into the Input pane, or load a text or HTML file with File. URL loads from servers that allow cross-origin requests.
  2. Click Encode to escape special characters, or Decode to turn references back into characters.
  3. Copy the result, Download it as encoded.txt or decoded.txt, or Clear both panes.

What Encode changes

CharacterBecomesWhy it must be escaped
&&amp;Starts a character reference. Replaced first, so nothing is escaped twice in one pass.
<&lt;Starts a tag.
>&gt;Ends a tag; escaped for symmetry and older parsers.
"&quot;Ends a double-quoted attribute value.
'&#39;Ends a single-quoted attribute value.

Everything else is left as it is, including accented letters, symbols and emoji: café © 2026 — 😀 comes out unchanged. A page served as UTF-8 (<meta charset="utf-8">) displays them correctly, so turning them into references only makes the source harder to read.

Example

<p class="note">Tom & Jerry's "show"</p>

encodes to:

&lt;p class=&quot;note&quot;&gt;Tom &amp; Jerry&#39;s &quot;show&quot;&lt;/p&gt;

Placed in a web page, that encoded string shows the original code as text rather than creating a paragraph, which is what you want when publishing code samples.

How Decode reads tricky input

Decoding uses your browser’s own HTML parser, so it follows the HTML parsing rules exactly, including the error-recovery cases. Tags in the input are treated as plain text and kept, never run. These results were produced on this page:

InputDecodedRule
&#169; &#xA9; &#x1F600;© © 😀Decimal and hex references.
&amp &copy &lt3& © <3Legacy names work without a semicolon.
&notit;¬it;The legacy name &not matches first.
&bogus;&bogus;Unknown names are left alone.
&AMP;, &apos;&, 'Both are defined names.
&#128;€Codes 128–159 are mapped as Windows-1252.
&#0;, &#x110000;�Invalid code points become U+FFFD.

Escaping and security

Inserting untrusted text into a page without escaping is the classic cause of cross-site scripting (XSS). Escaping these five characters is the right defence for text between tags and for attribute values in quotes. It is not enough inside <script> blocks, event handler attributes, style attributes, unquoted attributes or URLs such as href="javascript:…", which need their own encoding or validation. The OWASP XSS prevention cheat sheet lists the rules for each context. In application code, prefer your template engine’s automatic escaping over manual replacement.

Common problems and fixes

SymptomCauseFix
Page shows &amp;lt; or &amp;quot;Text was escaped twice, for example once on save and again in the template.Decode once here, then escape only when writing HTML.
Encoding &amp; gives &amp;amp;Encode treats existing references as plain text.Decode first if the input is already partly escaped.
A reference shows literally in the browserThe name is misspelt or unknown, e.g. &nbps;.Check the name in the HTML Standard’s list, or use the numeric form.
&nbsp; breaks an XML or RSS fileXML has no HTML named references.Use &#160; or the character itself.
URL query string still breaksHTML escaping does not percent-encode.Use the URL Encoder for parameters, then HTML-escape the full URL.

Frequently asked questions

Why does the encoder use &#39; instead of &apos;?

Both mean an apostrophe in HTML today, but &apos; was not defined in HTML 4, so the numeric &#39; is understood by every HTML parser and email client.

Should I encode accented letters and emoji?

Not for a page served as UTF-8, the standard encoding for the web. Numeric references are only worth it when a file must stay pure ASCII, for example for an older system that mangles other characters.

Is decoding safe with untrusted HTML?

Yes. The input is parsed as text inside a detached element and the result is shown in a plain text box, so tags and scripts in it are never rendered or run.

What is the difference between HTML escaping and URL encoding?

HTML escaping protects characters that are special to the HTML parser. URL (percent) encoding protects characters that are special in a URL, turning a space into %20. A link inside HTML may need both.

Is my text uploaded?

No. Encoding is a simple text replacement and decoding uses the browser’s parser; both run on your device and nothing you enter is sent anywhere.

Guides

Related tools