HTML Entity Encoder/Decoder
Escape text for HTML, or decode entities back into plain characters.
- Runs in your browser
- Nothing is uploaded
- Free, no sign-up
Only & < > and quotation marks are escaped. This is all that is needed to show text safely inside HTML.
About this tool
Turn the characters that have special meaning in HTML into entities so they display as text, or decode entities back into the characters they stand for. Choose whether only the essential characters are escaped, or every non-ASCII one too.
How to use it
- Choose Encode or Decode.
- When encoding, pick essential characters only, named, decimal or hexadecimal.
- Paste your text and copy the result.
The five characters that matter
Escaping exists because a few characters mean something to an HTML parser:
| Character | Entity | Why it needs escaping |
|---|---|---|
& |
& |
Starts every entity, so a bare one can swallow the text after it |
< |
< |
Starts a tag |
> |
> |
Ends a tag, so it is escaped for symmetry |
" |
" |
Ends a double-quoted attribute value |
' |
' |
Ends a single-quoted attribute value |
Essential mode does exactly this and leaves everything else alone. It is all you need to show text safely in a page served as UTF-8.
Escaping is for one context only
Entities are correct for HTML text and attribute values. They are the wrong tool elsewhere:
- Inside a
<script>block, content is not entity-decoded at all, so<would appear literally. Put data there as JSON, with<escaped as\u003c. - In a URL, special characters are percent-encoded instead: see the URL encoder.
- Escaping does not make untrusted HTML safe to insert. It makes text display as text. Letting a user's HTML through needs a sanitiser, not an encoder.
Named, decimal or hexadecimal
Named references such as é and © are readable in source. HTML 4 defines 252 of them, which is what this tool knows. Characters without a name are left as they are.
Decimal (é) and hexadecimal (é) references work for every Unicode character, and a single reference covers an emoji that is two UTF-16 code units in JavaScript.
If your page declares UTF-8, which it should, you rarely need any of them beyond the essentials. Reach for numeric references when the text may be saved or transmitted in an encoding you do not control, such as an email template or a file passed through an older system.
What decoding does and does not do
Decoding replaces references that end in a semicolon with their characters, in a single pass: &lt; becomes <, not <. Anything unrecognised, and bare ampersands like the one in AT&T, are left as written.
Numeric references between 128 and 159 are read the way browsers read them, as Windows-1252 characters, so – is an en dash. Out-of-range or surrogate values become the replacement character.
Frequently asked questions
Why ' for an apostrophe and not '?
' is not part of HTML 4 and is not understood by some older parsers and email clients. The numeric form works everywhere.
Does it decode newer entities such as ✓ or →?
It knows the 252 references of HTML 4, which includes →, ♥ and €. Names added in HTML5, such as ✓, are left unchanged.
How do I write a non-breaking space?
Use , which is U+00A0. In Named mode a non-breaking space in your text is converted to it, so it stays visible in the source.
Should I escape text before putting it in a database?
No. Store the original text, and escape for the output context when you render it. Storing escaped text leads to double-escaping and makes searching harder.
Related tools
URL Encoder & Decoder
Percent-encode and decode URLs, full strings or single components.
HTML Formatter
Indent messy HTML, or minify it for production.
Text to Binary Converter
Turn text into binary, octal, decimal or hex bytes, and back again.
Markdown to HTML Converter
Convert Markdown to HTML and back, with a live preview.