Encoding Tools

HTML Entity Encoder / Decoder

Encode or decode HTML entities, from angle brackets to symbols.

Browser workspace
LOCAL PROCESSING

Input stays in this browser while you use the tool.

About this tool

The HTML Entity Encoder / Decoder converts text to and from HTML entities. An HTML entity is a short piece of text that starts with an ampersand and ends with a semicolon, and that stands for a single character. For example, < stands for the less-than sign, & for the ampersand and © for the copyright sign.

Entities exist for two reasons. First, a few characters have a special meaning in HTML: the less-than and greater-than signs open and close tags, the ampersand starts an entity, and quotation marks end the value of an attribute. To show such a character as plain text on a page, you write it as an entity. A tag that you want readers to see, not the browser to run, is written as <p>. Second, entities let you write characters that are hard to type or that your file encoding might not support, such as symbols, accented letters and emoji.

The same character can be written in three ways: by name (©), by decimal number (©) or by hexadecimal number (©). All three give the copyright sign. Named entities are easier to read, and numeric ones work for any character, including those that have no name.

The encoder turns characters into entities, so that text can be placed safely inside an HTML page. The decoder does the opposite and turns entities back into the characters that they stand for. Escaping text correctly is one of the main defences against cross-site scripting, but only when it is done once and for the right place, as the common errors below explain. The conversion runs in your browser, so your text is processed on your own device and is not sent to the BitToolsKit server.

Use cases

  • Show HTML code on a web page. Encode a snippet such as <div class="card"> before you paste it into a tutorial, a blog post or documentation, so that the browser displays it instead of running it.
  • Escape user-written text before you place it in HTML. Comments, names and search terms can contain angle brackets and ampersands that must not be read as markup.
  • Fix text that shows entities on screen. If a page shows & or " as literal text, decode it to see what was meant and find where it was encoded twice.
  • Read data copied from HTML source, feeds or APIs. Titles and descriptions often arrive with entities in them. Decoding turns them back into readable text.
  • Write special characters safely. Insert a copyright sign, an em dash, a euro sign or an emoji into HTML or an email template without depending on the file encoding.
  • Prepare attribute values. A quotation mark inside a value in double quotes ends the value early, and encoding it avoids that.
  • Check what an entity means. Decode a numeric entity such as € to see the character behind it.
  • Clean imported content. When you move text between a CMS, a database and templates, decode and encode it once in a controlled way.

How to use

  1. Choose whether you want to encode text into entities or decode entities into text, if the tool shows that choice.
  2. Type or paste your text into the Input box. To encode, paste the plain text. To decode, paste the text that contains entities such as <, © or ©.
  3. Click Run tool.
  4. Read the result in the Output box. When you encode, the special characters are replaced by entities. When you decode, the entities are replaced by the characters.
  5. Check the result against the place where you will use it. Text that is going into an HTML page needs to be encoded exactly once.
  6. Click Copy output to copy the result, Download to save it as a file, or Clear to start again.

Encode once and decode once. Running the encoder on text that is already encoded turns < into <, and the result no longer displays as you intended. If you work with entities inside a URL, use the URL Encoder / Decoder, because URLs use a different kind of encoding.

Examples

Example 1: Show a snippet of HTML as text

Input (encode):
<p class="note">Fish & Chips</p>
What an encoder produces:
&lt;p class=&quot;note&quot;&gt;Fish &amp; Chips&lt;/p&gt;
The angle brackets, the quotation marks and the ampersand are replaced. Some encoders leave the quotation marks unchanged.

Example 2: An apostrophe

Input (encode):
Tom's cafe
What an encoder produces:
Tom&#39;s cafe
Some encoders write &#x27; instead of &#39;. Both mean the same character. The name &apos; works in HTML5, but older HTML versions do not know it, so a number is safer.

Example 3: Named, decimal and hexadecimal entities

Input (decode):
&copy; &#169; &#xA9;
What a decoder produces:
© © ©
Three ways of writing the same character.

Example 4: Letters and symbols outside plain ASCII

Input (encode):
Café — €5 ©
As named entities:
Caf&eacute; &mdash; &euro;5 &copy;

As numeric entities:
Caf&#233; &#8212; &#8364;5 &#169;

If your page is saved as UTF-8, you can usually write these characters directly and encode only the special ones.

Example 5: An emoji

Input (decode):
&#128512; and &#x1F600;
What a decoder produces:
😀 and 😀
The decimal number 128512 and the hexadecimal number 1F600 are the same value.

Example 6: Text that was encoded twice

Input (decode):
&amp;lt;b&amp;gt;
After one decode:
&lt;b&gt;

After a second decode:
<b>
If a page shows &lt;b&gt; as visible text, the text was encoded twice. Find the place where it was encoded the second time and remove that step.

Example 7: A non-breaking space

Input (decode):
price&nbsp;5
What a decoder produces:
price 5
The space looks normal but is the character U+00A0, not the ordinary space U+0020. In JavaScript, the text a followed by U+00A0 and b is not equal to a followed by a normal space and b.

Example 8: An entity without a semicolon

Input (decode):
&notit;
What a browser-style decoder produces:
¬it;
A few old entity names, including &not, are recognised even without the semicolon, so the start of &notit; is read as the not sign. Always write the semicolon, and encode a literal ampersand as &amp;.

Common errors

Entities appear as visible text on the page, such as &amp;lt;

The text was encoded twice. The first round changed < into &lt;, and the second round changed the ampersand of that entity into &amp;. Decode once to see the first stage, then remove the extra encoding step in your code or template.

Encoding by hand in the wrong order

When you replace characters yourself, replace the ampersand first. If you replace < with &lt; first and the ampersand afterwards, you turn &lt; into &amp;lt;. A proper encoder handles the order for you.

Decoded text is placed into a page as HTML

Decoding turns &lt;script&gt; back into a real tag. If you then insert that text into a page as markup, for example with innerHTML, the browser treats it as code. Insert untrusted text as text, with textContent, or keep it encoded.

Encoding does not protect text inside JavaScript, URLs or CSS

HTML entities work for text between tags and for quoted attribute values. Inside a script block, a URL or a style rule, the browser does not decode entities, and other characters matter. Use encoding that matches the place, for example URL encoding for addresses.

A missing semicolon changes the meaning

Browsers recognise some old entity names without a semicolon, so a text such as &notit; is read as the not sign followed by it. Always write the semicolon, and encode every literal ampersand as &amp;.

The apostrophe entity &apos; fails in an old system

HTML5 knows &apos;, but HTML 4 and some old email clients do not. Use the numeric form &#39; to be safe.

A name does not work because of its capitalisation

Entity names are case-sensitive. &Amp; is not an entity and stays as text, while &amp; and &AMP; work. Check the exact spelling and case of the name.

&nbsp; behaves differently from a space

It decodes to the non-breaking space U+00A0. Visitors see a normal space, but a string comparison with a regular space fails, and it prevents a line break at that place. Replace it with a normal space if you need to compare or split the text.

A number in the range 128 to 159 gives an unexpected character

HTML treats numeric references in that range, such as &#150;, as characters from the old Windows-1252 table, so &#150; becomes an en dash and not a control character. Numbers that are zero or above 1114111 become the replacement character. Use the correct Unicode number for the character you want.

Everything is encoded, although the page is UTF-8

On a page saved as UTF-8 you can write accented letters, symbols and emoji directly. Encoding them is allowed but unnecessary and makes the source hard to read. Encode only the characters with a special meaning, and encode more only when the encoding of the file or the channel is uncertain.

Frequently asked questions

What is an HTML entity?

It is a piece of text of the form &name; or &#number; that stands for one character in an HTML document. For example, &lt; is the less-than sign, &amp; is the ampersand and &#169; is the copyright sign.

Why do I have to encode the less-than sign and the ampersand?

Because HTML gives them special jobs. A less-than sign starts a tag and an ampersand starts an entity. To show them as text, you write &lt; and &amp;, so the browser does not read them as markup.

What is the difference between named, decimal and hexadecimal entities?

They are three ways to write the same character: by name, as in &copy;, by decimal number, as in &#169;, and by hexadecimal number, as in &#xA9;. Named entities are readable, and numeric ones work for every character, including those without a name.

Does encoding prevent cross-site scripting?

It is one of the main defences when you place untrusted text between tags or inside quoted attribute values, as long as you encode once, with the right escaping for that place. It does not protect text inside script blocks, URLs or CSS, and it does not replace the automatic escaping that modern frameworks and template engines provide.

What is the difference between HTML entities and URL encoding?

HTML entities such as &amp; make characters safe inside an HTML document. URL encoding, such as %26, makes characters safe inside a web address. They are different systems, and a value can need both at different stages.

Why does &nbsp; not behave like a normal space?

It is the non-breaking space, the character U+00A0. It looks like a space and stops a line from breaking there, but it is not equal to the ordinary space U+0020, so comparisons and splits can behave differently.

Should I use &apos; for an apostrophe?

It works in HTML5 and in XML, but HTML 4 and some old email clients do not know it. The numeric entity &#39; is understood everywhere.

Do I need to encode accented letters and emoji?

Not if your page is saved and served as UTF-8. You can write them directly. Entities are useful when the encoding of a file or a channel is uncertain, or when you want the source to show a symbol by name.

How many named entities exist?

HTML5 defines about 2,100 named character references that end with a semicolon, plus a small group of old names that browsers also accept without one. Common tools support the frequently used names, and the numeric form works for every character.

Is my text uploaded to a server?

No. The tool runs in your browser and works on your device. As a general habit, avoid pasting passwords, API keys or private tokens into any online tool.

Related tools

Share this page