Skip to content

HTML Entity Encoder & Decoder - Encode HTML Entities Online

Plain Text
HTML Entities

Encode and Decode HTML Entities

HTML gives a few characters special meaning: < starts a tag, & starts an entity and " ends an attribute value. To show them as text they must be written as entities. Paste text in Encode mode to escape it, or paste HTML source in Decode mode to see the characters it represents. Everything runs in your browser.

Example

Encoding this snippet so it can be shown inside a page:

<a href="/search?q=fish&chips">Café's menu</a>

gives:

&lt;a href=&quot;/search?q=fish&amp;chips&quot;&gt;Caf&#xE9;&#39;s menu&lt;/a&gt;

Put that inside a <pre> or <code> block and the browser shows the original markup instead of rendering a link.

Named vs Numeric Entities

Named entities such as &copy; are easier to read in source. Numeric entities such as &#169; (decimal) or &#xA9; (hex) can represent any Unicode character and work in XML too, where only the five basic named entities exist. The encoder always writes hex numeric entities for non-ASCII characters, and &#39; for the apostrophe, because &apos; is not defined in HTML 4.

Related Tools

For text going into a URL use the URL encoder, and for string literals in JSON, JavaScript or SQL use string escape. Each context has its own rules, and HTML entities do nothing useful in a URL or a JSON string.

Related Tools

Frequently Asked Questions

Which characters does the encoder change?
The five that matter in HTML: & becomes &amp;, < becomes &lt;, > becomes &gt;, " becomes &quot; and ' becomes &#39;. Every non-ASCII character is also written as a hex numeric entity, so é becomes &#xE9; and 😀 becomes &#x1F600;. The output is pure ASCII.
Do I need to encode accented letters and emoji?
Not on a page served as UTF-8, which is almost every page today. Only & < > and quotes inside attributes have to be escaped. Encoding the rest is useful when the text has to survive a system that mangles non-ASCII, such as an old CMS, a Latin-1 database or some email pipelines.
Which named entities can it decode?
Numeric entities in decimal (&#169;) or hex (&#xA9;) always decode. Named entities are limited to a common set: amp, lt, gt, quot, apos, nbsp, copy, reg, trade, mdash, ndash, hellip, the curly quotes, bull, prime, laquo, raquo, euro, pound, yen and cent. Others, such as &eacute;, are left unchanged.
Does this protect against XSS?
Escaping & < > " ' is the right defence for text placed between tags or inside a quoted attribute. It is not enough inside a script block, an unquoted attribute, a URL such as href="javascript:...", or CSS, which each need their own encoding. In application code, let your template engine or framework escape output; use this tool to inspect and debug.
Why does my page show & instead of &?
The text was encoded more than once. Each pass turns the & of an existing entity into &amp;. Decode until the text stops changing, then fix the code path that escapes text a second time, often a template that escapes values the application already escaped.