HTML Entity Encoder / Decoder

Encode special characters to HTML entities or decode them back — instant, free, private

Input Text
Encoded Output
Encoded HTML Input
Decoded Output

Common HTML Entities Reference

CharNamed EntityNumericHexDescription
&&&&Ampersand
<&lt;&#60;&#x3C;Less than
>&gt;&#62;&#x3E;Greater than
"&quot;&#34;&#x22;Double quote
'&apos;&#39;&#x27;Apostrophe
 ·&nbsp;&#160;&#xA0;Non-breaking space
©&copy;&#169;&#xA9;Copyright
®&reg;&#174;&#xAE;Registered
&trade;&#8482;&#x2122;Trademark
&euro;&#8364;&#x20AC;Euro sign
£&pound;&#163;&#xA3;Pound sign
¥&yen;&#165;&#xA5;Yen sign
&mdash;&#8212;&#x2014;Em dash
&ndash;&#8211;&#x2013;En dash
&hellip;&#8230;&#x2026;Ellipsis

What are HTML Entities?

Preventing XSS attacks

Encoding user input before inserting it into HTML prevents cross-site scripting (XSS) attacks. Characters like <, >, and & that could be interpreted as HTML tags or script injections are safely converted to their entity forms.

Named vs numeric

Named entities like &amp; are human-readable. Numeric entities like &#38; work for every Unicode character, even those without a named entity. Hex form &#x26; is also valid.

Special characters

HTML entities represent characters that would break HTML markup if inserted literally — or characters that are hard to type on a keyboard. The standard entities &lt;, &gt;, and &amp; are required in all valid HTML documents.

Frequently Asked Questions

HTML entities are special character sequences used to represent characters that have special meaning in HTML or that cannot be typed directly. They start with & and end with ;. For example, &lt; represents the less-than sign (<), and &amp; represents the ampersand (&).

You should encode HTML whenever displaying user-generated content to prevent XSS (cross-site scripting) attacks. Characters like <, >, and & must be encoded when output in an HTML context. Also encode when embedding HTML in XML, JSON strings, email bodies, or when storing HTML in databases.

Named entities use a word or abbreviation: &amp; for &, &lt; for <. Numeric entities use the character's Unicode code point as a decimal (&#38;) or hexadecimal (&#x26;) number. Named entities are more readable; numeric entities work for any Unicode character even when a name doesn't exist.

In JavaScript, encode HTML using a DOM method: const el = document.createElement('div'); el.textContent = userInput; return el.innerHTML; — the browser handles encoding automatically. Alternatively: str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'). Use DOMPurify for security-critical sanitization.

The characters that must always be encoded in HTML are: & (ampersand) → &amp;, < (less than) → &lt;, > (greater than) → &gt;. In attribute values, " must be encoded as &quot;. Without encoding, these characters break HTML parsing.

HTML entity decoding converts HTML entity sequences back to their original characters. For example, &lt;script&gt; becomes <script>. Browsers do this automatically when rendering HTML. You may need to decode programmatically when processing HTML strings in templates, APIs, or server-side code.

&nbsp; is the HTML entity for a non-breaking space (Unicode U+00A0). Unlike a regular space, a non-breaking space prevents the browser from inserting a line break at that position. It also is not collapsed like regular spaces. Commonly used to add visible spacing or to prevent text from wrapping at specific points.

If an HTML attribute value is wrapped in double quotes, single quotes do not need encoding. If wrapped in single quotes, single quotes must be encoded as &#39; or &apos;. When inserting user-supplied values dynamically into attributes — especially in templates — encode both quote types for safety. Use the "Encode quotes too" option above.

Related Tools