Cipher Utility

HTML Encode and Decode

E-04

Text to HTML entities and entities back to text. Runs in your browser; nothing is sent anywhere.

Encode:

How HTML encoding works

  1. Find the characters HTML treats as code.
  2. Replace each with its entity.
  3. Leave the rest of the text alone.
  4. The browser shows the entity as the character.

Worked example

<b> = ?

Replace the two angle brackets:

< → &lt;   > → &gt;

&lt;b&gt;

Cipher Utility reference card Catalog no. E-04

What HTML encoding is

In HTML, a few characters have a job. < starts a tag, & starts an entity, and quotes end an attribute value. To show those characters as plain text, for example to print a code sample on a web page, you write them as HTML entities instead. The browser displays the entity as the character and does not treat it as markup.

<p class="note">Tom & Jerry's "café"</p> &lt;p class=&quot;note&quot;&gt;Tom &amp; Jerry&#39;s &quot;café&quot;&lt;/p&gt;

Common HTML entities

CharacterNamedNumericMeaning
&&amp;&#38;Ampersand
<&lt;&#60;Less than
>&gt;&#62;Greater than
"&quot;&#34;Double quote
'&apos;&#39;Apostrophe
No-break space&nbsp;&#160;Space that keeps words together
©&copy;&#169;Copyright sign
€&euro;&#8364;Euro sign

Numeric entities work for any Unicode character: &#233; is é, written in decimal, and &#xE9; is the same in hex.

Basic or all

Basic encodes the five characters that matter in HTML: & < > " and '. Everything else stays readable. All also turns every character outside plain ASCII into a numeric entity, and the slash into &#x2F;, which helps when the text passes through a system that cannot handle UTF-8.

Decoding entities

Switch to HTML to Text to turn entities back into characters. The decoder understands named entities (&eacute;), decimal ones (&#233;) and hex ones (&#xE9;). It decodes one level at a time, so text that was encoded twice, such as &amp;lt;, needs two passes.

Questions about HTML entities

Which characters must be encoded in HTML?

The ampersand & and the less-than sign < always matter, because they start entities and tags. Inside attribute values, quotes need encoding too. The greater-than sign > is encoded by convention. This tool encodes all five: & < > " and '.

What is the difference between &amp; and &#38;?

Nothing in the result. &amp; is a named entity and &#38; is a numeric entity for the same character, code 38. Named entities are easier to read; numeric ones work for any character.

Do I need to encode accented letters and emoji?

Not on a page saved as UTF-8, which nearly all are today. Choose All under Encode if your text goes somewhere that only handles plain ASCII; every non-ASCII character then becomes a numeric entity.

Does encoding HTML protect against XSS?

Encoding text before you put it into an HTML page is one of the main defenses against cross-site scripting, because a script tag becomes harmless text. It is not enough on its own inside JavaScript, URLs or CSS, which each need their own escaping.

Is my text sent to a server?

No. Encoding and decoding run in your browser with JavaScript, and nothing you paste leaves your device.