2026-10-22 · 6 min read · Rahul Chitturi
- html
- entities
- debugging
The HTML entities page encodes by putting the text into a textarea and reading innerHTML. It decodes by assigning the box to that textarea's innerHTML and reading the value. An empty string returns an empty string before either step. A space is not empty, so it is kept. Nothing trims the box.
The sample <div>flashman & friends</div> encodes to <div>flashman & friends</div>. Quotes are not part of that escaping.
Escape three characters, and a no-break space
& becomes &. < becomes <. > becomes >. A double quote stays a double quote. An apostrophe stays an apostrophe. é and 🙂 stay themselves. A newline stays a newline, not a numeric character reference. A tab stays a tab. A no-break space becomes .
Text that is already encoded is encoded again. a&b becomes a&amp;b. Decode is the opposite direction, and it runs once. &amp; becomes &, not &. Run decode a second time if you wanted the ampersand.
- Expect quotes to survive encode.
- Expect > to become >.
- Expect a no-break space to become .
- Decode once, then look again.
Decode names the browser actually knows
& is &. & is also &. < is <. ≪ is not. That name is U+226A, the character ≪. > and even > without a semicolon are >. <div> without a semicolon on the last name is still <div>. &unknown; is left as the characters &unknown;.
Numeric forms work. ' and ' and " are the quotes encode refused to create. is a newline. is also a newline, because a textarea value does not keep a carriage return. � and a code point past Unicode become the replacement character. 😀 is 😀. 🙂 is 🙂.
Leave tags as text
The decoder is a textarea, so a tag in the box is not an element. <b>bold</b> comes back as that text. </textarea><b>x</b> comes back as that text too. <script>alert(1)</script> decodes to the characters of a script tag. It does not run.
Use the HTML entities tool for this pass, the Markdown editor when you need the sanitized HTML of a document, the XML tool when the brackets are markup rather than text, and diff when an encode and a later decode are not the original string. The usual miss is a second encode, a no-break space, or the name Lt.