Find your next tool

Browse tools or search by task

Explore JSONToonPro

Encoding & Decoding Tools

HTML Encode Online – Escape HTML Entities

Encode special characters into safe HTML entities online. Escape angle brackets, ampersands, quotes and Unicode text in your browser.

Runs locally in your browser. Nothing you paste is uploaded.

HTML Encode workspace
Plain text / HTML
0 chars
HTML Encoded
Result appears here...

How HTML Encoding Works

Paste text to escape markup-sensitive characters into HTML character references. This is useful when displaying source text inside an HTML document. Select the output appropriate to the exact context where it will be inserted.

Characters That Need Escaping

Ampersands and angle brackets need attention in text, and quotes matter in attributes. Escaping protects a character’s textual meaning. It does not transform an entire untrusted document into a safe application.

Named vs Numeric HTML Entities

Named references such as & and numeric references such as & can represent the same character. Browser support and parsing context determine interpretation. Preserve the semicolon to avoid ambiguous parsing.

HTML Encoding and XSS Safety

HTML escaping is context-specific. JavaScript, CSS and URL contexts need their own handling, and a dangerous URL remains dangerous when quoted. Prefer safe DOM text APIs and reviewed sanitizers where rich HTML must be accepted.

HTML Encoding Examples

The literal text <b> becomes &lt;b&gt; so it can be displayed rather than parsed as a bold element. Do not repeatedly encode content that is already escaped unless a second layer is deliberately needed.

More examples and technical details

What HTML Entities Are and Why They Exist

An HTML parser reads a document looking for structure. When it sees a less-than sign it assumes a tag is starting, and when it sees an ampersand it assumes an entity reference is starting. If your content genuinely contains those characters as text, the parser has no way to tell the difference, and your paragraph about "a < b" silently becomes a malformed element.

Entities solve this by giving every problem character an alternative spelling that contains no structural characters. An entity begins with an ampersand, names the character either by keyword or by code point number, and ends with a semicolon. The parser resolves it back to the original character at the moment it builds the text node, so the reader sees exactly what you intended.

The Characters You Must Escape

Five characters do the damage. Two of them, the ampersand and the less-than sign, are dangerous anywhere in an HTML document. The others matter depending on where the text lands.

& -> &amp; always, and escape it FIRST
< -> &lt; always, it starts a tag
> -> &gt; for safety and symmetry
" -> &quot; required inside double quoted attributes
' -> &#39; required inside single quoted attributes

Order is not optional. If you escape the less-than sign before the ampersand, the ampersand you just introduced gets escaped again and < turns into &amp;lt; which renders as visible text rather than a symbol. Always replace the ampersand first, then everything else.

Escaping and Cross-Site Scripting

Escaping user input before it reaches a page is the primary defence against cross-site scripting. An attacker who can get raw markup into your HTML can run JavaScript in your users' sessions. Encoding removes the ability of the input to change the shape of the document.

Raw input:
<script>fetch('/api/keys').then(r=>r.text())</script>
 
Escaped:
&lt;script&gt;fetch(...)&lt;/script&gt;
 
The browser now prints the text instead of executing it.

The critical subtlety is that escaping is context dependent. There is no single correct encoding, only the correct encoding for the place the value lands:

  • HTML body. Escape the five characters above. This is what an HTML encoder does.
  • Attribute value. Escape the same set and always quote the attribute. An unquoted attribute can be escaped by a space alone.
  • Inside a script block. HTML escaping does not help. You need JavaScript string escaping, and the safest approach is to serialise the value as JSON rather than interpolating it.
  • Inside a URL attribute. Percent-encode the value and validate the scheme, since javascript: URLs survive HTML escaping untouched.
  • Inside CSS. CSS has its own escaping rules and its own injection vectors. Prefer not to interpolate user data into styles at all.
Escaping is a defence, not the only defenceUse the framework's own escaping wherever possible, because it knows the context. Avoid APIs that insert raw markup, and add a Content Security Policy so that a missed escape does not become an immediate compromise.

Named, Numeric, and Hexadecimal Entities

The same character can be written three ways. All three render identically, and the choice is about readability and compatibility.

Named: &amp; readable, HTML only, about 2200 defined names
Numeric: &#38; decimal code point, works in XML and HTML
Hexadecimal: &#x26; hex code point, matches Unicode notation U+0026

XML predefines only five names (amp, lt, gt, quot, apos), so anything generating XML, RSS, or SVG should prefer numeric references. Note also that &apos; was added in HTML5 and is unreliable in very old HTML4 parsers, which is why security libraries tend to emit &#39; for the apostrophe instead.

HTML Entity Reference Table

Named entities are easier to read, numeric entities work everywhere including XML where only five names are predefined. Both forms always end with a semicolon.

CharacterNamed entityNumeric entityDescription
&&amp;&#38;Ampersand
<&lt;&#60;Less than, opens a tag
>&gt;&#62;Greater than, closes a tag
"&quot;&#34;Double quotation mark
'&apos;&#39;Apostrophe or single quote
(space)&nbsp;&#160;Non-breaking space
©&copy;&#169;Copyright sign
®&reg;&#174;Registered trademark sign
™&trade;&#8482;Trademark sign
 –&ndash;&#8211;En dash
…&hellip;&#8230;Horizontal ellipsis
€&euro;&#8364;Euro sign
£&pound;&#163;Pound sign
°&deg;&#176;Degree sign
×&times;&#215;Multiplication sign

Working on something related? Browse every free developer tool on the site, including a HTML decoder, URL encoder, Base64 encoder, and text utilities. Everything runs entirely in your browser, so nothing you paste is ever uploaded.

Frequently asked questions

How do I encode HTML entities?

Paste text in Encode mode and copy the escaped output.

Which characters should be escaped?

Escape markup-significant characters for the destination context, especially ampersands, angle brackets and attribute quotes.

Is HTML encoding the same as URL encoding?

No. HTML uses character references; URL encoding uses percent-encoded bytes.

Does encoding alone prevent all XSS?

No. Correct handling depends on the insertion context, and rich HTML needs sanitization.

Is text uploaded?

No. Input is processed in this browser tab and is not uploaded by the tool. Copy and download are actions you control; ordinary page analytics do not receive tool input.