← Developer

HTML Entity Encoder / Decoder

Escape special characters as named, decimal, or hex entities, or turn entities back into readable text; both sides update live.

Plain text or HTML

HTML entities

Type on either side; the other updates live.

Entity reference

Ampersand && · & · &
Less than <&lt; · &#60; · &#x3C;
Greater than >&gt; · &#62; · &#x3E;
Double quote "&quot; · &#34; · &#x22;
Apostrophe '&#39; · &apos; (HTML5 only) · &#x27;
CharNamedDecimalHexDescription

About this tool

This HTML entity encoder and decoder converts special characters into HTML character references and back, live, in both directions. Type or paste HTML or text on the left and the escaped version appears on the right; paste entity-laden markup on the right and the readable text appears on the left. You choose named entities (&eacute;), decimal (&#233;), or hexadecimal (&#xE9;) output, and whether to escape only the five characters that break HTML (& < > and both quotes) or every character outside plain ASCII as well. A filterable reference lists about 150 named entities with their numeric equivalents. It is for web developers escaping user content or code samples, writers pasting into CMS fields that mangle Unicode, and anyone debugging text that arrived full of &#39; and &nbsp;.

How it works

Encoding walks the text one Unicode code point at a time (so emoji and other astral characters become a single reference such as &#x1F600; rather than two surrogate halves). The characters & < > and the double quote always become &amp; &lt; &gt; &quot;; the apostrophe becomes &#39; because &apos; was not part of HTML 4. With the non-ASCII option on, every code point above 127 is written as its named entity if one is in the built-in table of roughly 150 common names (Latin-1, punctuation, currency, arrows, Greek, math), otherwise as a numeric reference. Decoding matches &name; &#decimal; and &#xhex; references, tolerates a missing semicolon on the legacy names browsers accept without one (amp, lt, gt, quot, apos, nbsp, copy, reg), and remaps numeric references 128 to 159 to their Windows-1252 characters as the HTML standard requires. Unknown names are left untouched.

Frequently asked questions

Should I use &apos; or ' for an apostrophe?

&apos; was not defined in HTML 4, so older browsers, notably Internet Explorer 8 and earlier, rendered it literally. HTML5 does define it, but ' has always worked everywhere, which is why this tool emits ' in named mode. In XML and XHTML both forms are valid.

Which characters must be escaped in HTML?

The ampersand must always be written as & in text and attribute values. The less-than sign must be escaped as < in text and should be in attributes too; the greater-than sign is escaped by convention. Inside a double-quoted attribute escape the double quote as ", and inside a single-quoted attribute escape the apostrophe as '. Non-ASCII characters do not need escaping as long as the page is served as UTF-8.

What is the difference between named, decimal, and hex entities?

They are three spellings of the same character: &eacute;, é, and é all render as é. Named entities are readable but only about 2,200 exist, and the less common ones need an HTML5 parser. Numeric references work for every Unicode code point in any HTML or XML parser, so they are the safer choice for machine-generated markup and for XML, which knows only five names.

Why does – decode to an en dash instead of a control character?

Code points 128 to 159 are C1 control characters with no printable form, but documents created on Windows often use those numbers meaning the Windows-1252 characters at the same positions. The HTML standard therefore tells browsers to remap them: – becomes the en dash (U+2013), ™ becomes the trademark sign, € becomes the euro sign, and so on. This tool applies the same table.

Related tools

JSON Formatter · Base64 Encode / Decode · URL Encode / Decode · Regex Tester · Hash Generator · UUID Generator · JWT Decoder · Color Converter · Password Generator · Number Base Converter · QR Code Generator · Chmod Calculator

Browse all Developer Tools, or go back to every free tool on HeroYears.