HTML Entity Encoder

Encode text as HTML entities to show code safely on a page, or decode &, < and © back to text.

Runs in your browser. Nothing is uploaded.

How to use the HTML Entity Encoder

  1. Paste HTML or text into the left box, or press Load example.
  2. Choose Encode to entities or Decode entities.
  3. When encoding, choose how much to encode. The basic five special characters are enough for HTML; non-ASCII characters can also be turned into named or numeric entities.
  4. The result appears on the right as you type.
  5. Copy the result into your page, template or email.

Show code and special characters safely in HTML

If you write <div> in a web page, the browser treats it as a tag, not text. If a product name contains & or a quote, it can break your HTML. Encoding these characters as entities, such as &lt;div&gt;, makes the browser display them literally. Decoding does the reverse, turning entity-filled text from a CMS export or an API back into readable characters.

Three levels of encoding

  • Only & < > “ ’: the minimal, safe choice for modern UTF-8 pages. Text stays readable, and nothing can be mistaken for markup.
  • Also non-ASCII, with names: characters like é, ©, — and € become named entities (&eacute;, &copy;, &mdash;, &euro;), with numeric references for anything without a name. Useful for systems that can’t store UTF-8.
  • Also non-ASCII, as numbers: every character outside ASCII becomes a hex reference such as &#xE9;, the most compatible form.

Decoding

Decoding understands numeric references in decimal (&#169;) and hex (&#xA9;), and the commonly used named entities: punctuation, currency, arrows, maths symbols, Greek letters and accented Latin letters. If the text contains a name that isn’t recognised, it’s left as it is and listed, so nothing is silently lost.

When you need this

Writing tutorials or documentation that show HTML code, putting user-generated text into email templates, cleaning up text exported from a CMS, or fixing a feed where &amp; appears literally. To escape text for code rather than HTML, use String Escape. Everything runs in your browser.

Frequently asked questions

What are HTML entities?

Entities are codes that represent characters in HTML, such as &lt; for <, &amp; for & and &eacute; for é. They let you show characters that would otherwise be read as HTML markup, or that are hard to type.

Which characters must be escaped?

In HTML text and attributes, the five that matter are & < > " and '. Escaping them prevents text from being read as tags or breaking out of an attribute. Everything else can be written directly when the page uses UTF-8.

Does escaping protect against XSS?

Escaping untrusted text with these five characters is the core of preventing cross-site scripting in HTML text and quoted attributes. But context matters. JavaScript, URLs and CSS each need their own escaping. Use your framework's built-in escaping for user input.

Named or numeric entities?

Named entities like &copy; are easier to read. Numeric ones like &#xA9; work for every character, including emoji, which have no names. Both are understood by all browsers.

Is my text uploaded?

No. Everything happens in your browser.

Tutorials