πŸ“ Text

HTML Encoder

Paste plain text or raw HTML below, special characters are instantly encoded into safe HTML entities.


  

About the HTML Encoder

Characters that carry special meaning in HTML, &, <, >, " and ', get swapped for their named entity equivalents so the result can be dropped safely into markup or an attribute without breaking the page.

Turn on "Encode all non-ASCII characters" if you also need accented letters, emoji, and anything past code point 127 converted into numeric entities like &#233;, handy for older systems that expect strict ASCII output.

Why the ampersand is replaced first, and why that order matters

The encoder runs five sequential .replace() calls, and the very first one turns every literal & into &amp;. That ordering isn't arbitrary β€” since every entity this tool inserts (&lt;, &gt;, &quot;, &#39;) itself contains an ampersand character, encoding & anywhere but first would re-encode the entities the tool had just inserted a moment earlier, turning &lt; into the broken double-encoded &amp;lt;. Doing the ampersand pass before any other character avoids that entirely, which is the same rule any correct manual HTML-escaping implementation has to follow.

The apostrophe uses a numeric entity, not &apos;

Single quotes are encoded as &#39; rather than the more readable named entity &apos;. This is deliberate: &apos; is valid in XML and HTML5, but it was never part of the original HTML 4 named-entity table, so older parsers, some XML-unaware HTML processors, and a handful of legacy tools don't recognize it. The numeric form &#39; resolves to the same apostrophe character in every HTML version back to HTML 2, so it's the safer default when you don't control what will eventually parse the output.

Non-ASCII encoding handles emoji correctly, not just accented letters

When "Encode all non-ASCII characters" is on, the tool doesn't loop over the string by index β€” it uses Array.from(text), which iterates by full Unicode code point rather than by raw UTF-16 code unit. That distinction matters for anything outside the Basic Multilingual Plane, like most emoji: a naive for loop over string indices would split a four-byte emoji into its two orphaned surrogate halves and encode each one separately, producing two broken, meaningless numeric entities where one correct one was needed. Iterating by code point instead means an emoji like πŸŽ‰ is read as a single unit and encoded as one valid decimal entity, &#127881;, that decodes back to the exact same character.

This covers the same character set security libraries treat as unsafe

The five characters this tool escapes by default, &, <, >, ", and ', are the same minimal set most HTML-context output-encoding libraries (including the ones referenced in OWASP's XSS prevention guidance) treat as the baseline that must be escaped before untrusted text is inserted into an HTML page or attribute. Encoding just these five is enough to stop a string like <script>alert(1)</script> from being interpreted as executable markup if it were pasted into a page as plain text content β€” though this tool doesn't attempt to sanitize or block anything, it only performs the character substitution, so it's on you to actually use the encoded output in place of the raw text.

Both quote characters are escaped, even though only one is usually needed

Both the double quote and the single quote get replaced regardless of which one your target markup actually uses to delimit an attribute value. This is a deliberate over-encode: since the result might end up inside attr="value" or attr='value' depending on how the destination markup is written, and the tool has no way of knowing which quote style will wrap the output, escaping both removes the ambiguity rather than making you specify a quoting context up front. The tradeoff is a slightly more escaped-looking result than strictly necessary for plain text content between tags, where neither quote character is actually dangerous β€” but for attribute-safe output, escaping both is the only choice that's correct in every case.

Frequently Asked Questions

Why is the ampersand encoded before the other characters?

Because every entity this tool produces (like &lt; or &quot;) contains an ampersand itself. Encoding the ampersand first, before inserting any other entities, prevents those newly-inserted entities from being encoded a second time into a broken, double-escaped result.

Why does the apostrophe become &#39; instead of &apos;?

&apos; is valid in XML and HTML5 but was never part of the original HTML 4 named-entity table, so some older or stricter parsers don't recognize it. The numeric reference &#39; resolves to the identical apostrophe character in every version of HTML, making it the more broadly compatible choice.

Does the non-ASCII option handle emoji correctly?

Yes. The tool iterates the text by full Unicode code point using Array.from() rather than by raw UTF-16 code unit, so multi-byte characters like emoji are read as a single unit and converted into one correct numeric entity, instead of being split into two broken surrogate halves the way a naive character-by-character loop would handle them.

Does encoding my text make it safe from XSS by itself?

Encoding the five characters this tool targets is the standard baseline for making text safe to insert as HTML content or into an attribute, but the tool only performs the character substitution β€” it doesn't sanitize, validate, or automatically apply the result anywhere. You still need to use the encoded output in place of the raw text wherever it's rendered.

Is my text sent to a server when I use this tool?

No. Encoding runs entirely in your browser with plain JavaScript string methods; nothing you type or paste is transmitted anywhere.