HTML Entity Encoder
encode and decode HTML entities for safe HTML embedding
By Bikram NathLast updated
Paste text containing HTML special characters and get back a safely escaped string ready for embedding in markup. Most useful when injecting user-supplied content into HTML templates: input `<script>alert(1)</script>` returns `<script>alert(1)</script>`, text the browser renders literally instead of executing. The decoder direction reverses pre-escaped strings from API responses or CMS exports where ampersands and angle brackets have already been entity-encoded.
Try it now — free, instant, no signup
What is HTML Entity Encoder?
This tool takes a raw string and replaces characters that carry structural meaning in HTML, specifically `<`, `>`, `&`, `"`, and `'`, with their named entity equivalents (`<`, `>`, `&`, `"`, `'`) or numeric references. Running `AT&T <wireless>` through it returns `AT&T <wireless>`, which is safe to place inside a paragraph, an attribute value, or any text node without disrupting surrounding markup.
Developers reach for an entity encoder when they need a one-off conversion without writing code. The same result is achievable in Python with `html.escape()`, in Node.js with the `he` library, or in a browser console with a two-liner using `document.createElement('div').innerHTML`. This tool is faster for spot-checks, paste-and-verify workflows, or when you are on a machine without those runtimes installed.
One precise technical boundary: the minimum safe set for HTML text nodes is `&`, `<`, and `>`. For attribute values you additionally need to encode the wrapping quote character. A string placed inside `onclick` is decoded by the HTML parser first, then evaluated as JavaScript, so entity-encoding a payload destined for a script context does not prevent execution. Entity encoding is the correct defence only for text nodes and attribute values, not for script or style contexts.