Skip to content
Devtoolry

HTML Entity Encode / Decode

Encode special characters as HTML entities or decode entities such as & and < back to text. Escape user content safely before adding it to a page.

Runs in your browser · Nothing uploaded · No sign-up

Something not working, or missing a feature? Send feedback

About the HTML Entity Encode / Decode

Characters such as <, > and & have special meaning in HTML. Encoding them as entities lets you display code and user text safely; decoding turns entities back into readable characters.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the HTML Entity Encode / Decode

  1. Choose Encode or Decode.
  2. Paste the text or HTML.
  3. Optionally encode all non-ASCII characters, then copy the result.

Example

Show code on a web page

Input

<a href="/search?q=tom&jerry">Tom & Jerry's</a>

Result

&lt;a href=&quot;/search?q=tom&amp;jerry&quot;&gt;Tom &amp; Jerry&#39;s&lt;/a&gt;

Encoded this way, the browser displays the tag as text instead of creating a link.

Common mistakes

  • Encoding twice. Encoding &amp; again gives &amp;amp;, which shows up literally on the page. Encode raw text once, at the point where it is inserted into HTML.
  • Using HTML escaping inside scripts or URLs. Entities protect HTML text and attributes. Values placed in JavaScript or in a URL need JavaScript string escaping or URL encoding instead.
  • Decoding untrusted input before display. Decoding turns &lt;script&gt; back into a real tag. Never insert decoded text from users into a page as HTML.

Works well with the HTML Entity Encode / Decode

Frequently asked questions

Does encoding protect against XSS?

Encoding text before inserting it into HTML is a key part of preventing XSS, but the right escaping depends on where the text goes (HTML, attributes, URLs or scripts).

Why encode non-ASCII characters?

Only when the page or system cannot handle UTF-8. Modern pages served as UTF-8 do not need it.

Named or numeric entities?

Both work in every browser. Named entities such as &amp; are easier to read; numeric ones such as &#233; work for any character, including those without a name.

Which characters must be encoded?

In text, & and <. In attribute values, also the quote character that delimits the value. Encoding > and both quotes everywhere is simplest and always safe.