HTML Entity Encode / Decode

Encode HTML special characters (<, &, ", ', >) as named or numeric entities, or decode them back to plain text. Auto-detects direction.

Example: <p>Hello & world</p>&lt;p&gt;Hello &amp; world&lt;/p&gt;

HTML entity encoding replaces special characters that would otherwise be interpreted as HTML markup. < becomes &lt;, & becomes &amp;, and so on. This is required when displaying user-generated content as plain text inside a web page — without it, you've got an XSS vulnerability.

The tool auto-detects: if the input contains entity references, it decodes; otherwise it encodes.

Use cases

Displaying code samples on a webpage

If you want to show <div> as text rather than render it, encode the angle brackets first.

Sanitising user input

Before inserting user-typed content into the DOM, entity-encode to prevent script injection. Modern frameworks do this automatically; raw HTML strings need manual escaping.

Reading raw API responses

Some APIs return entity-encoded HTML in JSON values. Decoding makes them human-readable.

Sharing URLs with ampersands in chat

Some chat tools render & in URLs as broken entities. Encoding the share URL once before pasting fixes that edge case.

Embedding HTML inside attributes

Rich tooltips and data-attributes that hold HTML need their content entity-encoded so the outer parser doesn't get confused.

Frequently asked questions

What's the difference between named and numeric entities?

Named: &lt;, &amp;, &quot;. Numeric: &#60;, &#38;, &#34;. Both work; named are more readable, numeric work for any character including ones without a named entity.

Does it encode every special character?

The five must-encode HTML chars: <, >, &, ", '. Other characters (em dash, copyright) are passed through unchanged — modern HTML handles them as UTF-8.

How does decoding work?

The tool uses the browser's own HTML parser via a hidden textarea. Whatever the browser decodes is what you get — guaranteed correct for any valid entity reference.

Is this the same as URL encoding?

No — different escape sets. URL encoding uses %xx hex; HTML entity encoding uses &name; or &#nn;. Use URL encoding for URL components; HTML encoding for HTML content.

Embed our tools on your website

Free for any site. No signup. Iframe loads from our servers and stays up-to-date automatically.

📋 Embed the Word Counter

Copy this snippet:

Live preview:

📋 Embed this HTML Entity Encode / Decode

Copy this snippet:

Live preview:

Want more options? All embeddable tools →