HTML Encoder/Decoder

HTML entity encoding turns <, >, &, quotes, and other characters into &lt; and friends so a browser treats them as text, not markup. That is the first defence against reflected XSS when you must put untrusted strings into HTML. Encoding is not a CSP, not a sanitiser for rich HTML, and not encryption.

What the HTML encoder is for

If you drop user text into HTML without escaping, a less-than sign becomes a tag. That is XSS. This tool turns &, <, >, quotes and apostrophes into entities so the browser displays them instead of interpreting them.

It is not a sanitizer. It will not make a full HTML document safe. It will make a string safe to place in a text node or a quoted attribute.

Common uses

  • Escaping a name or comment before showing it in a template
  • Decoding entities copied from a CMS or email
  • Checking what a payload looks like after encodeURIComponent vs HTML encoding — they are different

What the output means in the real world

The encoded string is what you paste into an HTML text node or an attribute that your template will not escape a second time. Decode when you are reading a log or a stored blob and need the original characters. Do not decode attacker input and then drop it into innerHTML. If you need rich markup, use a vetted sanitiser, not this box.

How this fits into real work

OWASP XSS Prevention lists contextual encoding: HTML body, attributes, JavaScript, CSS, and URLs each need a different encoder. This page is the HTML-entity context. Using it inside a script tag is the wrong tool.

Modern frameworks (React text children, Vue mustache) escape by default. XSS returns when someone uses dangerouslySetInnerHTML or v-html with a string that was only 'kind of' encoded. Check the sink, not just the encoder.

Email HTML and older CMS fields still store raw user quotes. Entity-encoding on the way out is how a comment cannot become a script. Decode only in an admin view that is itself escaped.

How to use this tool

  1. Paste the raw text. Encoding is live.
  2. Copy the output into a context that expects HTML text, not into a JavaScript string without further thought.
  3. Use Decode only on text you already trust was entity-encoded, not on attacker HTML you hope to 'clean'.

Tips

  • Attribute context still needs quotes around the value. Encoding alone is not enough if you omit the quotes.
  • For rich HTML from users, use a dedicated sanitizer library, not this page.

Privacy & how it works

Everything happens inside your browser. The values you type are held in page memory only, are never sent to a server, and disappear when you close the tab. You can confirm this in your browser's network tab: the only request a tool makes is one that names the tool for a usage count, with nothing you typed in it. The tools also work with the internet disconnected.

Frequently asked questions

Does this stop XSS?
It stops XSS from interpolating raw text into HTML text or quoted attributes. It does not stop XSS from javascript: URLs, event handlers, or CSS. Context matters.

Browse other tools

All tools run entirely in your browser — nothing you type is sent to a server, except the optional HIBP 5-character hash prefix.