Format Code Now
/

HTML Encode and Decode

ED-08

Paste 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

  1. Paste your text or HTML into the input box.
  2. Press Encode to convert special characters, or Decode to convert entities back.
  3. For encoding, choose whether to convert only & < > " ' or every non-ASCII character too.
  4. Pick named, decimal or hex entities for the non-ASCII characters.
  5. 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 &#39;, 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 &eacute; and &euro;, or as decimal or hex numbers such as &#233; and &#xE9;. Emoji are written as one reference, such as &#128512;.

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 &#150; 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

MessageWhat it meansFix
The reference &#xD83D; at line 1, column 1 is half of a surrogate pair. Write the whole character as one reference, for example &#128512;.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 &#128512;.
The reference &#0; 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 &amp;, &lt;, &gt;, &quot; and &#39;. 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 &amp; and &copy; and numeric ones such as &#169; and &#xA9; turn back into characters. Names that are not in the built-in table are left unchanged.

What is the difference between &#39; and &apos;?

Both mean the apostrophe. &apos; is defined in XML and HTML5, but not in HTML 4, and very old browsers did not read it. &#39; 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 &#233; or in hex as &#xE9;. They work for any character, including ones with no name, and an emoji such as U+1F600 is written as one reference, &#128512;.

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 &#39;. 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.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.