HTML entity encoder and decoder

The HTML entity encoder and decoder converts special characters, invisible characters, and other non-ASCII characters into HTML entities, and decodes named entities and numeric codes back to text.
Input
Enter text to encode, or text with entities such as " or é to decode. Up to 1 MB.

Encoding and decoding run in the browser. Please enable JavaScript.

Everything runs in your browser; nothing is sent or stored.

  • Enter text to encode, or text with entities, in the "Text or HTML with entities" field, and click "Encode" or "Decode".
  • Under "Encoding", choose "Special characters only", "Named entities too", or "Every non-ASCII character as a number". An entity must end with a semicolon. Every character can also be written as a numeric code, for example the € sign as € (named entity €).
  • Below the result, the tool shows the number of characters encoded or the number of entities decoded, and the number of characters in the result.
  • When decoding, the tool also shows the number of entities that were not decoded and were left as they are, such as an entity with a name the tool does not recognize.
  • When the text contains invisible direction marks, the number of marks is shown below the result.
  • Copy the result by clicking "Copy".
  • The entities ‏ (right-to-left mark) and ‎ (left-to-right mark) are invisible direction marks. They control where punctuation and numbers appear in text that mixes a right-to-left language, such as Hebrew or Arabic, with English, for example a period at the end of a right-to-left sentence that ends with an English word.

Why encode characters as HTML entities

In HTML, five characters have a role in the code: the < character opens a tag and the > character closes it, the & character starts an entity, and double quotes and apostrophes open and close an attribute value. When text entered by users, such as a comment, a name in a form, or a search term, is shown on a page without encoding, the browser may read it as code. This way, an attacker can inject a script into the page that runs for other visitors, in an attack called XSS (Cross-Site Scripting). Encoding the five characters as entities makes the browser display them as text, and the result works both in the content of an element and in an attribute value inside quotes. The apostrophe is encoded as the numeric code &#39;, which every version of HTML recognizes.

Named entities and numeric codes

An HTML entity is written in one of three forms: a named entity, such as &copy;, a decimal code, such as &#169;, or a hexadecimal code, such as &#xA9;. Every character has a numeric code in Unicode, but only some characters have a named entity. The "Named entities too" option is useful when you need to spot characters in the code that are hard to tell apart, such as a non-breaking space, dashes of different lengths, and invisible characters. The "Every non-ASCII character as a number" option suits a system that accepts only ASCII characters, for example a field or a template that does not store accented letters correctly. In numeric encoding, a letter such as é becomes a 6-character code, &#233;.

Double encoding and one-pass decoding

When text is encoded twice, for example by code that encodes a value that was already encoded, or by a plugin that encodes content that was saved encoded, the page shows the entities themselves instead of the characters, such as &quot; instead of a double quote. The tool decodes in one pass, so &amp;lt; becomes &lt; and not <. Each time you decode the result again, one layer of encoding is removed, and the number of decodes needed to get back the original text is the number of times the text was encoded. The right fix is to find where the second encoding happens, and to encode each value only once, when it is displayed on the page.

Common entities and the characters they represent

  • &amp;the & character, which starts an entity.
  • &lt;the < character, which opens a tag.
  • &gt;the > character, which closes a tag.
  • &quot;a double quote.
  • &#39;an apostrophe, as a numeric code.
  • &nbsp;a non-breaking space, which does not allow a line break in its place and does not merge with adjacent spaces.
  • &hellip;an ellipsis (three dots) as a single character.
  • &#233;the letter é as a decimal code.
  • &#xE9;the letter é as a hexadecimal code.

HTML entity encoder and decoder FAQ

Do I need to encode non-ASCII text, such as accented letters or non-Latin scripts, as entities?

No. In a page set to UTF-8 encoding, for example with a meta tag that has the charset="utf-8" attribute, there is no need to encode non-ASCII text, such as accented letters or non-Latin scripts, and encoding the special characters with the "Special characters only" option is enough. Encoding such text as numeric codes increases the page size and makes the code harder to read and edit.

Why was an entity not decoded?

An entity is not decoded when the tool does not recognize its name, when its numeric code belongs to a control character or an invalid character, or when the semicolon at the end of the entity is missing. The tool recognizes the common named entities, including entities for accented Latin letters, quotation marks, dashes, arrows, and currency symbols, but the HTML standard defines more than 2,000 names. You can replace a named entity that the tool does not recognize with the numeric code of the character.

Does HTML entity encoding protect against all XSS attacks?

No. HTML entity encoding does not protect against every XSS attack: inside a script tag, in CSS code, and in a URL placed in an attribute such as href, other rules apply. For example, a URL that starts with javascript: contains no character that gets encoded, so you also need to check that a URL starts with https:// or http://.

What is the difference between HTML entity encoding and URL encoding?

HTML entity encoding is used to display characters as text in HTML code, and URL encoding is used to write characters in a URL, for example a space as %20. When a URL with several parameters is placed in an href attribute, the & character between the parameters is written as &amp; under HTML rules. To encode values in a URL, use the "URL encoder and decoder" tool.

How do I find the direction marks in a text?

When you encode with the "Named entities too" option, each direction mark is replaced with a named entity, such as &rlm; or &lrm;, or with a numeric code, so the location of each mark is visible in the result. To remove direction marks, use the "Invisible character detector" tool.

What is the maximum size of text for HTML entity encoding or decoding?

The input can be up to 1 MB, for both encoding and decoding.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement