Skip to main content
SwiftTools

HTML Entity Encoder

Encode and decode HTML entities. Safely escape special characters to entities and decode entity-encoded text back to literal characters.

Special characters are converted to safe HTML entities.

About HTML Entity Encoder

Encode special characters like <, >, and & into safe HTML entities, or decode entity-encoded text back to their literal characters. Runs entirely in the browser, so nothing is uploaded.

How to use it

  1. 1Choose Encode or Decode.
  2. 2Enter your text or entity-encoded text.
  3. 3Copy the result.

When to use it

  • Safely placing HTML that contains <, >, or & inside another document or a data attribute.
  • Cleaning up entity-encoded paste that came from an editor or an email client.
  • Preparing snippet content for a CMS that stores raw markup.

Tips & best practices

  • Encoding protects display, not security - it is an escaping aid, not a substitute for proper sanitization on the server.
  • Decode first if you are unsure whether text is already encoded, to avoid double-encoding.
  • Smart quotes and dashes from chat apps can survive a naive copy; re-check the decoded output on sensitive content.

Examples

Encode

Input
<div class="a">A & B</div>
Result
&lt;div class=&quot;a&quot;&gt;A &amp; B&lt;/div&gt;

Decode

Input
&lt;code&gt;
Result
<code>

Frequently asked questions

How does encoding work?

It uses a hidden textarea: setting textContent then reading the value encodes; setting innerHTML then reading textContent decodes. This is a browser-native, reliable conversion.

Does it handle quotes?

Yes - double and single quotes are encoded to &quot; and &#39; as appropriate when encoding.

Does encoding hide my text from the server?

No - it only changes how the browser renders the characters. It is not a privacy or security control.