HTML Entities: Escape, Encode and Decode Safely
Short answer: HTML gives special meaning to <, >, & and quotes. To show them as text, write them as entities such as < and &. The HTML Entity Encoder & Decoder converts text to entities and decodes named and numeric entities back. Escaping user-provided text this way is a basic defence against injecting markup into a page.
What Encode changes
Encode escapes five characters: &, <, >, " and '. For example <p>Tom & Jerry's "show"</p> becomes:
<p>Tom & Jerry's "show"</p>
Tick Also encode non-ASCII to turn every character above U+007F into a numeric entity: café €5 <b> becomes café €5 <b>, and an emoji becomes a single entity such as 😀.
When to encode non-ASCII
Mostly when a page cannot be served as UTF-8. With UTF-8, which is the default today, accented letters, symbols and emoji can be written directly.
Decoding
Decoding understands named entities (©, €), decimal (€) and hexadecimal (€) ones. It uses the browser's own HTML rules, so:
&lt;decodes once, to<;- a few legacy entities such as
©work without the semicolon; - unknown names such as
&unknown;are left as they are; - impossible numbers like
�or�become the replacement character; - numbers 128 to 159 follow the HTML table for Windows-1252, so
€is the euro sign; becomes a non-breaking space, which looks like a normal space but is a different character.
Markup in the input is never interpreted or run. Decoding returns text only.
Double escaping
If text shows &lt; on a page, it was escaped twice and needs two decoding passes. The Swap button moves the output back into the input and flips the mode, which is a quick way to confirm that a round trip returns the original.
Escaping is not a complete defence
Escaping those five characters is the right way to put untrusted text between HTML tags, and it protects quoted attribute values. It is not enough inside a <script> block, a style block, an unquoted attribute or a URL. Those contexts need their own escaping, such as URL percent-encoding for links, or string escaping for JavaScript and JSON, which the String Escape & Unescape tool handles by context. For risky patterns in code, see AI-generated code insecure patterns.
How to encode and decode HTML entities with the tool
- Open the HTML Entity Encoder & Decoder.
- Choose Encode or Decode and paste your text.
- Tick "Also encode non-ASCII" if you need numeric entities.
- Copy the output. To look up a character code, use the ASCII Table; to tidy the markup, use the HTML Formatter.
Limits to know
- It escapes five characters, and is not a full sanitiser.
- It does not make values safe in script, style, unquoted attribute or URL contexts.
- Everything runs in your browser.
Frequently asked questions
Which characters does Encode change?
&, <, >, " and '.
How do I decode &?
Choose Decode.
Why do I see &lt; on my page?
The text was escaped twice.
Is a normal space?
No, it is a non-breaking space.
Is my text uploaded? No.