Toolstia / HTML entities encoder and decoder

HTML entities encoder and decoder

HTML entities let you write characters that would otherwise be read as markup. This tool works in both directions. Encode takes text or code and replaces the special characters with entities, so a snippet can be shown on a web page instead of being run by the browser. Decode turns entities such as &, © or — back into the actual characters.

It helps when you publish code samples, clean up text copied from page source, debug a string that shows & on screen, or prepare content for a system that cannot store Unicode. An option converts every character beyond basic ASCII to a numeric entity. The result appears instantly and can be copied with one click.

How it works

  1. Choose encode or decode.
  2. Paste your text.
  3. Copy the result.

Why encode

In HTML the characters < and > start tags, and & starts an entity. To show them as plain text, or to put code samples safely on a page, they must be written as &lt;, &gt; and &amp;.

Quotes

Double quotes become &quot; and single quotes become &#39;, which keeps attribute values from breaking when you put text inside them.

Non-English characters

Turning on the extra option writes characters such as é, ৳ or emoji as numeric entities, like &#233;. This is useful for old systems that cannot store them directly. Modern pages can usually use UTF-8 text without this.

Not a security guarantee

Encoding helps display text safely, but how you escape depends on where it goes. For web apps, use your framework's built-in escaping for each context.

What encoding produces

Encoding the text <a href="x">Tom & Jerry's</a> gives &lt;a href=&quot;x&quot;&gt;Tom &amp; Jerry&#39;s&lt;/a&gt;. Five characters are always replaced: the ampersand, less-than, greater-than, double quote and single quote. The ampersand is handled first so that the ampersands in the new entities are not encoded a second time.

The single quote becomes &#39; instead of &apos;. Both work in HTML5, but &apos; is not valid in HTML 4, so the numeric form is the safer choice.

Turning non-English characters into numbers

With the extra option ticked, every character above code point 126 is written as a decimal numeric entity. So Café ৳ becomes Caf&#233; &#2547;, and an emoji outside the basic range, such as the grinning face, is written as one entity, &#128512;, not as two halves of a surrogate pair.

On a modern page that declares UTF-8, this is rarely needed. It is mainly useful for old email systems, legacy databases or templates that corrupt non-ASCII text. It makes the markup longer and harder to read, so leave it off otherwise.

Decoding and the double-encoding problem

Decoding uses the browser's own HTML parser rules on the text, so it understands numeric entities and the full set of named entities, and it only reads them as data. Nothing in the input is run or displayed as a page.

A frequent bug is text that was encoded twice, which shows up on a page as &amp;lt; instead of <. Decoding it once gives &lt;, and decoding the result a second time gives <. The tool decodes one level each time, so you can repeat the step to see each layer.

The non-breaking space and other look-alikes

The entity &nbsp; decodes to a non-breaking space, which looks like a normal space but is a different character. If text decoded here refuses to match a search or a comparison in code, an invisible non-breaking space is a likely cause.

Similar look-alikes include the em dash &#8212; and the curly quotes. They decode correctly, but they are different characters from the plain hyphen and straight quote on your keyboard.

Where entity encoding is and is not enough

Encoding these five characters is correct for text placed in the body of an HTML page or in a quoted attribute value. It is not the right escaping for text inside a script block, a style block or a URL, where each context has its own rules. For URLs, use percent-encoding instead.

If you build pages with a framework or template engine, let its built-in escaping do this work for you, and use this tool to check what the output should look like.

Questions

Does decoding handle named entities?

Yes, such as &copy;, &nbsp; and &euro;, as well as numeric ones.

Is anything uploaded?

No. Everything is done in your browser.

Does decoding run scripts in my text?

No. The text is only decoded, never displayed as page content.

Is encoding the same as URL encoding?

No. URLs use percent codes, so use the URL encoder for those.

Which characters does encoding always replace?

The ampersand, less-than and greater-than signs, double quotes and single quotes. Everything else stays as it is unless you tick the non-English option.

Why did my accented letters not change when encoding?

They are only converted when the option for non-English characters is ticked. Otherwise they are left as normal text.

Can I decode numeric entities written in hexadecimal?

Yes. Forms such as &#xA9; and &#169; both decode to the copyright sign.

What happens to an entity the browser does not know?

Unknown names such as &madeup; are left as written, because they are not valid entities.

Is encoding enough to stop script injection on my website?

It is one part of the solution for text in HTML content. Use your framework's escaping for each place the data goes, and treat the output of this tool as a helper, not a security layer.