DevTools Pro · All tools · About

HTML Encoder/Decoder

About the HTML Encoder/Decoder

This HTML encoder and decoder converts special characters into HTML entities and turns entities back into readable text. Use it to show code samples on a web page, sanitize text before inserting it into markup, or read content that was escaped one time too many.

What are HTML entities?

An HTML entity is a text code that stands in for a character the browser would otherwise treat as markup. &lt; displays < instead of opening a tag, and &amp; displays a literal ampersand.

Entities come in three forms: named (&copy;), decimal (&#169;) and hexadecimal (&#xA9;). All three produce the same character, ©. Named entities are easier to read; numeric ones work for any Unicode character, including emoji like &#x1F600;.

Which characters does this encoder escape?

Encode mode escapes eight characters: &, <, >, ", ', /, the backtick and =. The first five are what HTML strictly needs; the last three are escaped as extra protection when text lands in unquoted attributes or older template engines.

For example, <a href="x"> becomes &lt;a href&#x3D;&quot;x&quot;&gt;. Pasting that into a page shows the tag as text instead of creating a link.

Encoding non-ASCII and keeping formatting

With "Encode Non-ASCII" on, every character outside the ASCII range is written as a hex reference, so café becomes caf&#xE9;. The output is pure ASCII, which helps with legacy systems, emails or files with an unknown character set.

"Preserve Formatting" is on by default and leaves whitespace exactly as typed. Turn it off and line breaks become <br>, tabs become four &nbsp; and double spaces become &nbsp;&nbsp;, so plain text keeps its layout once rendered. Decoding with it off reverses the conversion.

Double encoding and how to spot it

If you see &amp;lt; on a page, the text was encoded twice: the & of &lt; was escaped again. Decode it once to get &lt;, and a second time to get <. The fix in your code is to escape exactly once, at the point where text is written into HTML.

How to Use the HTML Encoder/Decoder

  1. Pick Encode or Decode under Operation Mode.
  2. Paste HTML, text or entity-encoded content into the Source HTML panel.
  3. Optionally turn off Preserve Formatting to convert line breaks to <br> and spaces to &nbsp;, or turn on Encode Non-ASCII (encode mode only) for ASCII-only output.
  4. Read the result in the output panel. It updates as you type and whenever you change an option.
  5. Click the copy icon to copy the result, or the trash icon to clear the input.

Frequently Asked Questions

Is my HTML uploaded to a server?
No. Encoding and decoding happen in your browser, and the decoder never inserts your input into the live page.
What is the difference between &nbsp; and a normal space?
&nbsp; is a non-breaking space: browsers do not collapse it or wrap a line at it. Several normal spaces in a row collapse into one when HTML is rendered.
Should I use named or numeric entities?
Either works in modern browsers. Named entities like &eacute; are easier to read, while numeric references work for every Unicode character and in XML, which only knows five named entities.
Does HTML encoding stop XSS attacks?
It stops injection when untrusted text goes into element content or a quoted attribute. Text placed inside <script>, style or URL attributes like href needs context-specific handling as well.
Why is Encode Non-ASCII hidden in Decode mode?
It only affects encoding. Decode mode already converts every numeric and named reference back to its character.
Do I need to encode characters if my page is UTF-8?
Only the markup characters (<, >, & and quotes) must be escaped. Accented letters and emoji can be written directly in a UTF-8 page.

Related tools