Skip to main content

HTML Encode/Decode

Encode special characters to HTML entities or decode them back.

Built and tested by Muhammad Irfan Liaqat · Updated

HTML Encode/Decode: key facts

  • Encodes the five characters that matter in HTML: & < > " and '
  • Decodes &amp; &lt; &gt; &quot; &#39; &nbsp; and numeric entities such as &#169; or &#xA9;
  • Named entities other than those, such as &copy;, are left as they are
  • Converts as you type; nothing is uploaded

What HTML encoding changes and why

HTML encoding replaces characters that have a special meaning in HTML with entities, so a browser shows them as text instead of reading them as markup. This tool encodes < as &lt;, > as &gt;, & as &amp;, double quotes as &quot; and single quotes as &#39;. Decoding reverses those, plus &nbsp; and numeric entities such as &#169; or &#xA9;.

Encode text when you want to show code samples on a web page, put user-supplied text inside HTML, or use quotes inside an attribute value. Decode it when copied text or an API response shows codes like &amp;amp; instead of the characters. Escaping output this way is the core defence against cross-site scripting (XSS), but in a real application let your framework or template engine escape output automatically rather than encoding strings by hand.

How to encode or decode HTML entities

  1. 1Paste your text into the input box
  2. 2Click Encode to convert special characters to entities, or Decode to convert them back
  3. 3Check the result in the output box
  4. 4Click Copy to copy it

Frequently Asked Questions

Why should I encode HTML?
So that characters such as < and & display as text rather than being treated as tags or entities. Encoding user input before inserting it into a page also stops injected scripts from running.
Which characters does the encoder change?
Five: < becomes &lt;, > becomes &gt;, & becomes &amp;, " becomes &quot; and ' becomes &#39;. All other characters are left as they are.
Which entities can it decode?
&amp;, &lt;, &gt;, &quot;, &#39;, &#x27; and &nbsp;, plus any numeric entity such as &#169; or &#xA9;. Other named entities, such as &copy;, are left unchanged.
What is an XSS attack?
Cross-site scripting (XSS) happens when an attacker gets their own script into a page that other people view, often through a comment or form field. Escaping user-supplied text before it is added to HTML prevents the browser from running it.
How do I show HTML code as text on a web page?
Encode it first, so <p> becomes &lt;p&gt;, and put the result inside <pre><code> tags. The browser then displays the tags instead of running them.
Is HTML encoding the same as URL encoding?
No. HTML encoding writes characters as entities such as &amp; for use inside a page. URL encoding writes them as percent codes such as %20 for a space, for use inside a link.
What is &nbsp;?
A non-breaking space: a space that stops two words from being split across lines. The decoder turns &nbsp; into an ordinary space.

Related Tools