HTML Encoder/Decoder

Easily convert special characters into HTML entities or decode them back to plain text. Use this free online tool to make your code web-safe and prevent HTML errors

Data to encode:

Example: <>

Data to decode:

Example: &lt;&gt;

An HTML encoder converts characters that have a special meaning in HTML into entities, so they are displayed as text instead of being read as markup. An HTML decoder turns entities back into the characters they stand for. Use it to show code samples on a web page, to safely include user text in HTML, or to read entity-filled text from a feed or database. It runs in your browser.

How to encode or decode HTML

  1. To encode, paste text into Data to encode and click Encode.
  2. To decode, paste text containing entities such as &lt; or &#39; into Data to decode and click Decode.

Which characters are encoded

The five characters that matter most are always encoded:

CharacterEntityWhy
<&lt;Starts a tag
>&gt;Ends a tag
&&amp;Starts an entity
"&quot;Ends a double-quoted attribute
'&#39;Ends a single-quoted attribute

This tool also encodes other punctuation as numeric entities (for example / as &#47;) and common symbols such as ©, € and ½ as named entities. That is more than browsers strictly need, but it is harmless and keeps the output plain ASCII.

Common problems

  • Double-encoded text such as &amp;lt; shows entities on the page instead of characters. It was encoded twice; decode once.
  • Encoding isn't enough inside scripts and URLs. HTML entities protect text in normal HTML content and attributes. Inside a <script> block or a URL you need JavaScript escaping or URL encoding instead.
  • Entities in plain-text contexts. Email subjects, JSON APIs and text files don't interpret entities, so &amp; appears literally. Only encode text that will be rendered as HTML.

Frequently asked questions

Does HTML encoding prevent XSS?

Encoding user-supplied text before inserting it into HTML content or quoted attributes is a key defence against cross-site scripting. It must match the context: script blocks, URLs and CSS need their own escaping. Templating engines that escape automatically are the safest option.

What is the difference between named and numeric entities?

Named entities use a name, like &copy; for ©. Numeric entities use the Unicode code point, in decimal (&#169;) or hex (&#xA9;). Both display the same character.

What is the difference between HTML encoding and URL encoding?

HTML encoding uses entities like &lt; so text displays correctly in a page. URL encoding uses %XX codes so text can travel inside a URL.