Home/Developer Tools/HTML Entity Encoder / Decoder
🔣

HTML Entity Encoder / Decoder

FREE

Escape < > & quotes as entities, or decode them back

Free · No sign-up required
Loading...

What the HTML encoder does

To show a < on a web page rather than start a tag, it has to be written as &lt;. This tool converts text to HTML entities (encode) and entities back to text (decode). It is how you display code samples on a page, put user-supplied text into HTML safely, and read what a garbled block of &#39; and &quot; actually says. It runs in your browser.

The five characters that must be escaped

CharacterEntityWhy
<&lt;Starts a tag
>&gt;Ends a tag (escape for symmetry and safety)
&&amp;Starts an entity
"&quot;Ends an attribute value in double quotes
'&#39; (or &apos;)Ends an attribute value in single quotes
Text: if (a < b && c > "d") { alert('hi'); } Encoded: if (a &lt; b &amp;&amp; c &gt; &quot;d&quot;) { alert(&#39;hi&#39;); }

Encoding these five in any text placed into HTML is what stops user input from being interpreted as markup — the basic defence against cross-site scripting (XSS).

Named, decimal and hex entities

  • Named: &copy; ©, &nbsp; non-breaking space, &mdash; —, &euro; €. HTML5 defines over 2,000 names.
  • Decimal: &#169; ©, &#8212; —. Works for any Unicode code point.
  • Hexadecimal: &#xA9; ©, &#x2014; —.

Since pages are UTF-8 today, most characters can be typed directly and only the five structural ones need entities. Entities remain useful for invisible characters (&nbsp;, &zwj;), for characters hard to type, and for source that must stay pure ASCII.

Common uses

  • Displaying HTML or code examples on a page, in a blog post or in documentation.
  • Escaping strings before inserting them into a template by hand.
  • Decoding text scraped from a page or an API that returned entities instead of characters.
  • Reading email subject lines or RSS titles that arrived double-encoded (&amp;#39;).
  • Writing title and alt attributes that contain quotes.

Encoding is context-specific

HTML entity encoding is correct for text between tags and inside attribute values. It is the wrong encoding for other contexts: a value going into a URL needs percent-encoding, one going into a JavaScript string needs JavaScript escaping, and one going into CSS needs CSS escaping. Use the URL & Base64 encoder for URLs. Modern frameworks (React, Vue, Django templates, Rails ERB) escape HTML automatically; this tool is for the cases where you are writing raw markup.

Frequently asked questions

Should I encode every non-ASCII character?

Not on a UTF-8 page — type é, 中, emoji directly. Encode only the five structural characters, plus invisible characters you want to make explicit.

Why does my text show &amp;amp; instead of &?

It was encoded twice. Decode it twice, or find where the second encoding happens (often a template engine escaping already-escaped data).

Is &apos; safe to use?

In HTML5 yes; in old HTML4 parsers it was not defined. &#39; works everywhere.

Does encoding protect against all XSS?

It protects text placed in HTML content and quoted attributes. Values placed in URLs, event handlers, script blocks or unquoted attributes need context-specific escaping — and never build HTML from untrusted input by string concatenation if a templating system is available.

What about &nbsp; in the decoder?

It decodes to a non-breaking space (U+00A0), which looks like a normal space but does not wrap. Replace with a regular space if that matters.

Is my text uploaded?

No. Encoding and decoding run in your browser.

More tools in this category

📋
JSON Tools
View tree, format, validate and minify JSON
📄
YAML Beautifier & Validator
Format YAML and find the line that breaks it
📋
XML Tools
Beautify, validate and convert XML to JSON
🗃
SQL Formatter & Minifier
Lay out SQL clause by clause, or collapse it to one line
📝
Markdown Tools
Preview Markdown, convert to HTML and generate tables
🔑
JWT Encoder & Decoder
Decode a JWT's header and payload, or sign one with HS256