HTML Entity Encoder / Decoder

Convert special characters to HTML entities (&, <, ©) or decode entities back to readable text — both directions, live.

955 views

How It Works

HTML reserves a handful of characters for its own syntax: < and > mark tags, and & starts an entity reference. If those characters appear literally inside content that gets inserted into a page — a comment, a username, a search query echoed back — the browser tries to parse them as markup instead of displaying them as text. Encoding converts them into their entity form (&lt;, &gt;, &amp;) so they render as the literal characters instead of being interpreted. Decoding reverses this, turning entities like &amp; or &#8217; back into the actual characters they represent.

This is not a cosmetic detail — it is a security control. If a comment box takes user input and inserts it into the page HTML without encoding it first, a visitor can type <script>...</script> and have that script actually execute in every other visitor's browser: this class of vulnerability is called Cross-Site Scripting (XSS), and encoding untrusted output before it touches HTML is the standard defense against it. For example, encoding the text 5 < 10 & 10 > 5 produces 5 &lt; 10 &amp; 10 &gt; 5, which displays correctly and cannot be mistaken for markup.

What You Should Know

  • Named vs. numeric entities represent the same character differently. &apos; (named) and &#39; (numeric) both mean a single quote, but named entities depend on the parser recognizing that specific name — numeric entities (decimal or &#x hex) are universally supported and safer for machine-generated output.
  • Encoding is not the only defense. It protects text content; attributes, URLs and inline JavaScript contexts need their own escaping rules, since a value inside href="javascript:..." or inside a <script> block is parsed under different rules than plain body text.
  • Conversion is local. This tool uses your browser's own DOM parser — nothing is uploaded or logged.
  • Not every server-side templating language auto-escapes by default. Some (like older PHP output or raw string concatenation) require you to call an escaping function explicitly — forgetting it is one of the most common sources of real-world XSS bugs.
  • Some entities look almost identical visually. A straight apostrophe (') and a typographic right single quote (&#8217;) render nearly the same on screen but are different byte sequences — a distinction that matters in code samples or URLs.

A concrete before/after: a comment field containing Nice post! 5 < 10, right? needs no special handling as plain text, but the moment it's inserted into an HTML template unescaped, a malicious visitor could instead submit <img src=x onerror=alert(1)> — encoding turns that into inert, visible text instead of an executing image-error handler.

Frequently Asked Questions

Why encode text before putting it in HTML?

An unescaped < or & in HTML content can be interpreted as markup, breaking the page layout or — far worse — allowing injected <script> or <img onerror> tags to actually execute (Cross-Site Scripting). Encoding to &lt; and &amp; keeps the text literal and inert, no matter what a user typed.

Does it handle named and numeric entities both?

Yes — decoding understands both named entities (&amp;copy;) and numeric ones, whether decimal (&amp;#169;) or hexadecimal (&amp;#x00A9;). All three represent the same © character; the tool normalizes any of them back to the actual glyph.

Why use a numeric entity instead of a named one, or vice versa?

Named entities (&amp;apos;, &amp;hellip;) are more readable in source code, but rely on the parser recognizing that exact name — a handful of less common ones have inconsistent support across older tools. Numeric entities (&amp;#39;, &amp;#8230;) are universally understood by every HTML parser regardless of age or vendor, which is why automated tools and sanitization libraries often prefer them.

Does encoding alone make my page safe from XSS?

It handles text nodes, but HTML has other injection contexts — inside an attribute value, inside a URL, inside a <script> or <style> block — each needs its own escaping approach, since the browser's parser switches rules depending on where it is in the document. Entity-encoding text content is one essential layer, not the whole defense; a broader "sanitizing" step that strips or rewrites entire tags is a separate, more opinionated tool for when you intentionally want to allow some limited HTML.

Is my text sent anywhere?

No — conversion happens instantly in your browser using the DOM's own parser; nothing is uploaded, logged or stored, which makes it safe to test real user-submitted content, including anything you suspect might contain an injection attempt.

Comments

No comments yet — be the first to write one!

Similar Tools