HTML Entity Encoder & Decoder
Safely escape text for inclusion in HTML or inside an attribute, or decode escaped entities back into plain characters. The encoder always escapes the five characters that can change the meaning of markup, and the decoder can read both the named and the numeric forms.
HTML text
Output
Ready — paste some input or load the sample.
100% Client-Side · Privacy First. This tool runs entirely inside your browser. Nothing you type is uploaded, logged or sent to a server — you can even use it offline.
Overview
HTML entities let you put a character that has a special meaning in markup into a document safely. The three that matter most are the ampersand, which starts an entity reference, the less-than sign, which opens a tag, and the greater-than sign, which closes one. Encoding them as &, < and > lets you display markup, control characters or characters from another script without the browser interpreting them. The same applies to quotation marks when a value is inserted into an HTML attribute. This tool encodes text to entities and decodes entities back to the original characters. The encoder always escapes the five characters that carry meaning in markup, while the decoder understands named entities such as as well as numeric and hexadecimal forms such as — and —. It is the tool to reach for when a value coming from a user, a database or a config file has to be embedded in HTML without becoming markup.
How to use the html entity encoder & decoder
- 1Paste the text or the markup fragment into the input panel.
- 2Pick encode or decode in the mode switch.
- 3In the decode direction, choose whether you want named entities such as & or numeric ones such as &.
- 4Read the notes for the length of the result and the list of characters that were escaped.
- 5Copy the output into your template, your email or your CMS field.
- 6Encode the ampersand first, so an already escaped value is never double escaped by accident.
Cheat sheet
The syntax you will use most, and what each part does.
| Pattern | What it means |
|---|---|
& |
The escaped ampersand. It has to be encoded first, otherwise the browser reads the raw ampersand as the start of an entity. |
< and > |
Angle brackets, the characters that would otherwise open or close a tag. |
" and ' |
Double and single quotes, needed when a value is placed inside an HTML attribute. |
|
A non-breaking space, which prevents a line break in the middle of a phrase. |
— |
A numeric entity, also written — in hexadecimal. Use it for characters with no named form. |
Encode ampersand first |
Encoding in the wrong order double-encodes the result and shows up as &lt; in the browser. |
Common mistakes
The browser still shows raw markup.
You encoded the wrong characters or skipped the angle brackets. Inside an attribute, quote marks also have to be escaped.
Text shows up as &lt; everywhere.
The text was encoded twice. Decode it once to get back to the original, and only encode when the value is about to be inserted into a document.
An email body breaks.
Email clients vary in their entity support. Stick to the basic named entities and numeric forms for anything unusual.
A database column fills with entities.
Encode at render time, not at write time. Storing encoded values makes every later query and comparison harder.
Worked examples
Markup shown as text
<script>alert(1)</script>
The angle brackets are escaped so the browser prints the tag instead of executing it.
An attribute-safe value
He said "hello" & left
The quotes and the ampersand are encoded so the value can sit inside a double-quoted HTML attribute safely.
Frequently asked questions
When should I encode HTML entities?
Whenever user supplied text is placed into a page, a template or an attribute. Escaping is what keeps a value such as <script> from becoming a tag instead of being shown as text.
What is the difference between named and numeric entities?
A named entity is readable and self-documenting, such as &, while a numeric one is a code point, such as &. Both render identically in a browser, and named entities are easier to maintain.
Does this protect against cross-site scripting?
It removes one of the ways an injection can happen, but it is not a complete defence. Context matters: a value that is safe inside a text node can still be dangerous inside an attribute or inside a script block.
Can I convert the other way round?
Yes. Switch the mode to decode and the tool turns <div> back into <div>, including the named and the numeric forms and the common HTML entities.
Which characters does the encoder escape?
The ampersand, the less-than and greater-than signs, the double quote and the single quote. The ampersand is always escaped first, so an already escaped value does not get double escaped by accident.
Why did my value end up as &lt;?
The text was encoded twice. The second pass escaped the ampersand of the first pass, so decode once rather than twice when you fix a double encoded value.
Does it work with email templates?
Yes, and it is worth doing. Email clients vary in how they decode entities, so encoding the characters that matter keeps the rendering predictable across Outlook, Gmail and Apple Mail.
Can I encode a whole HTML document?
Yes, and the result is a single escaped blob that any browser will display as source code. That is useful for sharing a snippet in a comment or in a log line.
Does the encoder touch non-ASCII characters?
No. A letter with an accent stays as it is, because UTF-8 pages render it correctly without an entity. Only the five markup characters are escaped.
Can I use the result inside a JSON string?
Yes, but the JSON escaping comes first, because the quote and the backslash of a JSON string have to be escaped before the HTML characters. Escaping in the wrong order produces a value that no longer parses.
What does the decoder do with an unknown entity?
It leaves it alone and reports it in the notes, so an entity that is not part of the standard set is not silently swallowed. That matters when you are cleaning up a legacy template.