My Tool Studio
Developer Tools·2 min read

HTML Entities: How to Encode and Decode Text

Some characters mean something to a browser, so dropping them into a page raw can break the markup. The HTML Encoder / Decoder turns characters like <, >, & and quotes into HTML entities, and turns entities back into plain text. It runs in your browser with no upload.

Hello WorldHello&nbsp;WorldHTML

What HTML entities are

Codes that stand in for characters.

An entity is a short code that a browser shows as a character instead of reading it as markup. Named entities use words, like &lt; for a less-than sign or &copy; for the copyright sign. Numeric references use a number, like &#169; for the same sign, or a hex value like &#x1F600; for an emoji.

If your page is saved as UTF-8, you rarely need entities for accented letters. Only &, <, > and quotes must be escaped. Named entities are easier to read, while numeric ones also work in XML, which defines only five named entities.

Encoding text

The five characters that matter.

Encode replaces & with &amp;, < with &lt; and > with &gt;. With Escape quotes ticked, the default, a double quote becomes &quot; and a single quote becomes &#39;, or &apos; if you pick that under Apostrophe as. Everything else is left alone. That is what you need to show a code sample on a web page or put text safely into an attribute. Untick Escape quotes for text that goes between tags, where quotes are harmless.

If you also want accented letters, symbols and emoji written as entities, set Non-ASCII as to Named where possible, Decimal or Hex. Named gives readable forms like &eacute; and falls back to a number when no name exists. Setting Encode to Every character (numeric) writes the whole text as numeric references. That helps when a system mangles anything outside plain ASCII.

Decoding entities

Every entity browsers know.

Decode understands every HTML5 named entity, from &amp; and &nbsp; to &eacute; and &hearts;, plus decimal and hex references. Emoji written as numeric references, such as &#128512;, come out whole instead of as two broken halves.

Decoding happens inside a detached text area, so tags in your input stay as text. A script or img tag is never run or fetched.

Fixing &amp;amp; on a page

The double-encoding problem.

When a feed or CMS shows &amp;amp; instead of &, the text was encoded twice. Tick Decode double-encoded text and click Decode to get back to the original in one step, then make sure your code escapes the text only once. Swap sends the output back to the input whenever you want to check a round trip, and Live mode converts as you type.

Looking up a single entity

A reference on the same page.

Below the tool, a searchable reference lists 215 common entities. Type a name, a character or a number, then click the named or decimal form to copy it. That is quicker than encoding a whole string when you only need the entity for a non-breaking space or an arrow.

Encoding is not a complete XSS defence

Context matters.

Escaping those five characters makes text safe inside element content and quoted attributes. It is not enough inside a script block, a style block, an unquoted attribute or a javascript: URL. Use your framework's escaping and a Content Security Policy as well.

Characters, not documents

Where this tool stops.

This page converts characters and entities only. To indent markup, use the HTML Beautifier, and to shrink it, use the HTML Minifier. For links, the URL Encoder / Decoder handles %XX escapes, which is a different kind of encoding.

Try it now

Open HTML Encoder / Decoder

The tool is one click away. No sign up, no upload, no payment.

Open HTML Encoder / Decoder