HTML Entities

Two-way conversion between text and HTML entities — prevent injection, handy for web pages and email templates. 100% client-side, data never leaves your browser.

Three ways to write the same character

HTML entities come in three forms, all of which render identically:

FormExampleNotes
Named&Readable, but only about 2,000 characters have names
Decimal&Works for any Unicode code point
Hexadecimal&Same coverage, more compact for high code points

Named entities are friendlier to read and edit; numeric forms are universal. Either way, the trailing semicolon is required.

Why escaping is not optional

Three characters have structural meaning in HTML and must be escaped whenever you want them displayed as text:

Quotes matter too inside attributes: escape " in double-quoted attributes and ' in single-quoted ones.

Escaping is not a substitute for sanitising

Converting < to &lt; renders HTML inert, which prevents many cross-site scripting attacks — but it is not sufficient on its own. Context matters: inside a JavaScript string, inside a URL, or inside a CSS value, the dangerous characters are different. Escape according to where the value is being placed, and prefer framework-provided escaping over hand-written replacements.

Everyday characters people look up

CharacterNamed entityNumeric
Non-breaking space&nbsp;&#160;
Ampersand&amp;&#38;
Less-than&lt;&#60;
Copyright&copy;&#169;
Em dash&mdash;&#8212;
Euro sign&euro;&#8364;

A non-breaking space looks like a space but stops a line break at that point — useful between a number and its unit, or inside a product name you do not want split.

Escaping twice is the most common mistake

Escaping is only correct once, at the moment a value is written into HTML. If the stored text already contains an escaped ampersand — Tom &amp; Jerry — and a template escapes it again, the result is Tom &amp;amp; Jerry and the visitor sees the literal characters &amp; on the page instead of an ampersand.

This shows up when the same value passes through several layers: a rich-text editor, a database round-trip, an API response, then a template. The fix is a rule rather than a patch — keep raw characters in storage, escape exactly once on output, and never escape in a layer that only forwards data.

Where entities are not decoded

<script> and <style> are raw-text elements: the HTML parser does not decode entities inside them, so writing &amp; in a script hands JavaScript the five characters &amp;, not an ampersand. Build strings there with ordinary characters and leave entity encoding to markup.

Inside attributes the rules are the same as in text, with one addition — whichever quote character delimits the attribute must be escaped, or it terminates the value early. Using single quotes around an attribute that contains a double quote avoids the problem entirely.

Always close the entity with a semicolon

HTML5 tolerates a missing semicolon in some positions, but the parser then takes the longest entity name it can match. That turns &notit; into &not; followed by it;, which renders as ¬it; instead of the intended text. Numeric forms are even riskier without a terminator, because the parser keeps consuming digits. Write the semicolon every time and the ambiguity disappears.

Related tools

Unicode converter ASCII table URL encoder

FAQ

When do I need HTML entities?
When characters like < > & appear in HTML, email templates or rich text, the browser parses them as tags or entities; converting them to entities avoids broken display or injection.
Is my text uploaded?
No. Everything happens locally in your browser; no data is sent anywhere.