HTML Encode and Decode
ED-08Paste text to turn the characters that matter in HTML into entities, or paste entities such as & and é to turn them back into text.
Runs in your browser. Nothing is uploaded.
Text or HTML
Result
How to use it
- Paste your text or HTML into the input box.
- Press Encode to convert special characters, or Decode to convert entities back.
- For encoding, choose whether to convert only & < > " ' or every non-ASCII character too.
- Pick named, decimal or hex entities for the non-ASCII characters.
- Copy the result.
What Encode converts
Encode always converts the five characters that matter in markup: ampersand, less-than, greater-than, double quote and apostrophe. The apostrophe is written as ', which every browser reads. With the second option, every character above U+007F is converted too. You can write them with names where the built-in table has one, such as é and €, or as decimal or hex numbers such as é and é. Emoji are written as one reference, such as 😀.
What Decode understands
Decode converts decimal and hex references and the named entities in its built-in table. The table holds the 252 names of HTML 4 (Latin-1 letters, Greek, arrows, math symbols and common punctuation), plus apos and a few HTML5 names. HTML5 defines about 2,200 names, so a name outside the table is left exactly as you typed it. Names need the closing semicolon. Numeric references from 128 to 159 are read as Windows-1252 characters, as browsers do, so – gives an en dash.
Encoding and security
Entity-encoding text makes it display as typed in HTML body text and in quoted attribute values. It is not a full defense against injection, because other contexts, such as URLs, scripts and style blocks, need their own encoding. Use your template engine's escaping for output in a real application and use this page for checking and one-off conversions.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
The reference � at line 1, column 1 is half of a surrogate pair. Write the whole character as one reference, for example 😀. | A reference points to half of an emoji-style character. Surrogate halves are not characters on their own. | Use one reference for the whole character, such as 😀. |
The reference � at line 1, column 1 is not a valid Unicode character (it must be between 1 and 1114111, or 10FFFF in hex). | The number is zero or above the largest Unicode code point. | Use a number from 1 to 1114111, or from 1 to 10FFFF in hex. |
Questions people ask
How do I encode special characters in HTML?
Paste the text and press Encode. Ampersands, angle brackets and quotes become &, <, >, " and '. That is enough to show the text literally in an HTML page. Choose the second option if you also want accented letters and symbols converted.
How do I decode HTML entities?
Paste text containing entities and press Decode. Named entities such as & and © and numeric ones such as © and © turn back into characters. Names that are not in the built-in table are left unchanged.
What is the difference between ' and '?
Both mean the apostrophe. ' is defined in XML and HTML5, but not in HTML 4, and very old browsers did not read it. ' works everywhere, so Encode uses it. Decode understands both.
What are numeric character references?
They write a character by its Unicode number, in decimal as é or in hex as é. They work for any character, including ones with no name, and an emoji such as U+1F600 is written as one reference, 😀.
Why was a named entity left as it was?
The decoder's table holds the 252 HTML 4 names plus a few more, not all 2,200 names HTML5 defines. A name outside it, or one missing its closing semicolon, stays as typed. A numeric reference always works.
Do I need to encode non-ASCII characters in HTML?
Not if the page is served as UTF-8, which is the normal case. Accented letters and emoji display correctly as they are. Encoding them is only needed for systems that cannot carry UTF-8, or when you want ASCII-only source.
About this tool
Encode always converts the five characters that matter in markup: & < > " and '. The apostrophe becomes '. With the second option, every character above U+007F also becomes an entity, using a name where the built-in table has one and a number otherwise. Decode handles decimal and hex references and the 258 names in the built-in table: the HTML 4 set, apos and a few HTML5 names. HTML5 defines about 2,200 names, so a name outside the table is left exactly as typed. Names need the closing semicolon. References 128 to 159 are read as Windows-1252 characters, as browsers do. Entity encoding makes text safe to show in HTML but is not a complete defense against injection in every context.