HTML Entity Encoder / Decoder
Encode HTML special characters (< > & " ') or decode them back to plain text.
- Free · no sign-up
- Instant results
- Privacy-friendly
Other Developer Tools
Why escaping exists
A browser cannot tell the difference between a < that begins a tag and a < you meant as a literal character. Escaping resolves that ambiguity: the character is replaced by an entity — < for <, > for >, & for &, " for a double quote, ' for an apostrophe — which the browser renders as the original symbol without ever treating it as markup.
This is why escaping is the foundation of preventing cross-site scripting. If user-supplied text containing a script tag is escaped before it reaches the page, the browser displays the words rather than executing them. Nearly every XSS vulnerability is a place where that step was skipped or undone.
Choosing a scope
Special characters only converts the five that carry meaning in HTML and leaves everything else untouched. This is almost always the right choice. Accented letters, CJK text, and emoji stay as readable UTF-8, which keeps your output legible and your file size down — and on any page correctly served as UTF-8, they render perfectly.
All applicable characters additionally converts every character with a named entity, so é becomes é and — becomes —. Reach for this only when output has to survive a pipeline you do not control: a legacy system that mangles non-ASCII, an email template of uncertain encoding, or a database column that is not UTF-8. It produces significantly larger output for no benefit on a modern, correctly configured page.
Escape at output, not at input
The most common architectural mistake is escaping data as it is saved. Store what the user actually typed and escape at the moment you render it. Escaping on the way in corrupts your data for every other consumer — an API response, a CSV export, a plain-text email, a search index — all of which now contain &quot; where a quote should be, and none of which want HTML entities.
It also causes double-encoding, the most familiar symptom of getting this wrong. Escape once and & becomes &. Escape the result again and it becomes &amp;, which renders on the page as the literal text &. If you are seeing &amp; or &quot; in your output, something in the chain is escaping data that was already escaped. Use the decode direction here to confirm how many layers deep it goes.
Context matters more than the escape itself
HTML escaping protects HTML body content. It is not sufficient — and sometimes not correct — elsewhere. Text going into a JavaScript string needs JavaScript escaping; a value going into a URL needs percent-encoding; a value in a CSS context needs CSS escaping. Applying HTML escaping to a URL parameter and calling it safe is a genuine and common vulnerability.
Unquoted HTML attributes deserve particular caution. Inside an unquoted attribute an attacker can break out with a space alone, without needing any of the five escaped characters. Always quote attribute values, and escape what goes inside them.