← All tools
// DEVELOPER

HTML Entity Encoder online

Encode text to HTML entities and decode HTML entities back to text.

HTML Entity Encoder logo
by
CHUNKY
MUNSTER
HTML ENTITY ENCODER / DECODER

Common HTML Entities

How to Use Hello & "World"

  1. Paste your text into the input area.
  2. Click Encode to convert all five XSS-relevant characters to HTML entities.
  3. Enable "encode all non-ASCII" to also convert accented and special characters.
  4. Switch to Decode mode to recover original text from HTML-encoded input.

HTML entity encoding is a primary defence against Cross-Site Scripting (XSS). When user-supplied text is rendered into an HTML page, every <, >, &, ", and ' must be escaped as their entity equivalents to prevent the browser from interpreting them as markup. This encoder handles the five essential characters plus optional full Unicode escaping.

XSS Prevention Through Encoding

An XSS attack injects a script tag — <script>alert('xss')</script> — into page content. If the server renders this string directly into HTML without encoding, the browser executes the script. HTML entity encoding transforms the same string to &lt;script&gt;alert('xss')&lt;/script&gt; — browsers display it as text, never executing it. Context matters: entity encoding is correct for HTML text content; attribute context requires additional rules.

Frequently Asked Questions

Is HTML encoding sufficient to prevent all XSS?

It prevents the most common vector but context matters. HTML entity encoding is correct for HTML body content. In JavaScript contexts, you need JavaScript escaping. In URL attributes, URL encoding. In CSS, CSS escaping. Use a context-aware sanitiser library for robust XSS prevention.

Why must & be encoded first?

If you encode < to &lt; first and then encode &, you would double-encode to &amp;lt;. Always encode the ampersand before other characters to avoid this.

Should I encode apostrophes?

Always encode apostrophes (') when the text appears inside a single-quoted HTML attribute. In HTML body text, apostrophes are safe without encoding, but encoding them defensively does no harm.

What is the difference between this and URL encoding?

HTML entity encoding is for text inside HTML markup. URL encoding (percent-encoding) is for query parameters and URL path segments. < in HTML becomes &lt;; in a URL it becomes %3C. Both represent the same character, but they are incompatible encoding schemes.

See also the HTML Decoder, HTML Encoder, and the HTML Formatter.