HTML entity encoder / decoder
Escape text to HTML entities or decode entities back to characters. Named, decimal and hex entities supported.
<a href="x">Tom & Jerry’s</a>
What this HTML entity tool does
Encode takes plain text and escapes the five characters that have meaning
in HTML — &, <, >, " and ' — into &, <, >, "
and '. The result can be dropped into element content or an attribute
and will display literally instead of being parsed as markup. Decode does
the reverse for named entities, decimal (©) and hexadecimal (©)
references. The logic is a pure string replace with no DOM involved, so it
behaves the same everywhere and runs entirely in your browser.
How to use it
- Pick Encode or Decode.
- Paste into the input box. The sample
<a href="x">Tom & Jerry’s</a>shows all the interesting characters at once. - The output updates as you type — notice the curly apostrophe
’in the sample is not touched, because it has no special meaning in HTML. - Click Copy.
The five characters and their entities
| Character | Named | Decimal | Hex | Why it is dangerous |
|---|---|---|---|---|
& | & | & | & | Starts an entity — © 2024 can render as © 2024 |
< | < | < | < | Opens a tag; <script> is the classic injection |
> | > | > | > | Closes a tag; escaped for symmetry and safety in attributes |
" | " | " | " | Ends a double-quoted attribute value |
' | ' (' in HTML5) | ' | ' | Ends a single-quoted attribute value |
Encoding the sample input gives:
<a href="x">Tom & Jerry’s</a>
Strictly, only & and < must be escaped in text content, and only the
matching quote inside an attribute. Escaping all five everywhere costs nothing
and removes the need to remember which context you are in, which is what
every templating engine (React, Vue, Jinja, Handlebars {{ }}) does by
default.
Common named entities the decoder knows
| Entity | Character | Entity | Character |
|---|---|---|---|
| non-breaking space | © | © |
® | ® | ™ | ™ |
… | … | — | — |
– | – | « » | « » |
€ | € | ° | ° |
Anything else — é, →, ♥ — must be written numerically
(é, →, ♥) to be decoded here. In practice, modern
UTF-8 pages rarely need named entities beyond the five above and ; you
can type → and ♥ directly.
Decoding gotchas
- Double-escaped text. Content that was escaped twice (common when a CMS
escapes on save and on render) shows
&lt;on the page. One decode pass turns it into<, a second into<. The tool decodes one level per run, so paste the output back in if you need both. - Case matters for names.
&is not a valid entity in HTML; the tool is lenient and decodes it, but browsers will not. - Missing semicolon.
© 2024is not decoded — the decoder requires the closing;. Browsers forgive some legacy names without it, which is exactly why unescaped&in URLs (?a=1©=2) can corrupt your links. - Numeric zero (
�) and out-of-range code points are left as-is rather than producing invalid characters.
Related tools and snippets
- URL encoder / decoder — the other escaping you need for
links:
&in anhrefneeds both percent-encoding rules and&. - JSON formatter & validator — JSON embedded in a
<script>tag needs<escaped as<, a different mechanism. - Case converter — normalize text before it goes into attributes or IDs.
- Text diff — spot the difference between a stored string and its escaped copy.
- Regex tester — test the
/[&<>"']/gpattern used by most escape helpers.
FAQ
Which characters must be escaped in HTML?
Five cover every context: & (ampersand), < and > (tag delimiters), and the two quote characters " and ' for attribute values. Encode mode converts exactly these five and leaves everything else, including accented letters and emoji, untouched.
What is the difference between named, decimal and hex entities?
They are three spellings of the same thing. ©, © and © all produce ©. Named forms are readable but limited to a fixed list; numeric forms work for any Unicode code point. Decode mode understands all three.
Why is the apostrophe encoded as ' and not '?
' was not part of HTML 4 and older browsers (Internet Explorer 8 and earlier) did not render it. The numeric ' works everywhere, so it is the safe choice; the decoder still accepts '.
Do I need to escape accented characters like é?
Not if your page is served as UTF-8 with a matching charset meta tag, which is standard today. Entities like é date from the era of Latin-1 pages. Encode mode therefore leaves them as literal characters.
Why was a named entity like é left untouched when decoding?
The decoder knows the common names (amp, lt, gt, quot, apos, nbsp, copy, reg, trade, hellip, mdash, ndash, laquo, raquo, euro, deg) plus every numeric form. Rare names outside that list are passed through unchanged — use the numeric equivalent such as é instead.
Is escaping HTML enough to prevent XSS?
It is the right defense for text and attribute values. It is not enough inside a script block, an inline event handler, a style attribute or a URL — each of those has its own escaping rules, and the safest option is not to put untrusted data there at all.