How Do You HTML Encode an Ampersand (&)?

The html encoding of "&" is &. The ampersand (&) is HTML encoded as &. The ampersand is the most important character to encode because it introduces all HTML entities. An unescaped & can cause parsing errors, broken entities, and XSS vulnerabilities.

Why Encode "&"?

The & character starts HTML entities (like &, <, ©). If you write "Tom & Jerry" in HTML without encoding, the browser tries to parse "& Jerry" as an entity reference. Encoding it as &amp; ensures the literal ampersand is displayed correctly.

Encoding Details

Character&
Encoded form&amp;
Encoding typeHTML encoding
Unicode code pointU+0026

Code Examples

JavaScript

// Using built-in text content (auto-escapes)
element.textContent = 'Tom & Jerry';

// Manual encoding
'Tom & Jerry'.replace(/&/g, '&');
// "Tom & Jerry"

Python

import html
html.escape('Tom & Jerry')
# 'Tom & Jerry'

Try It Yourself

Use our HTML Encoder to encode any character instantly.

Frequently Asked Questions

Why is & the most important character to encode?

Because & is the escape character itself. Every HTML entity starts with &. If & is not encoded, the parser may interpret the following text as an entity, leading to garbled output or security vulnerabilities.

Do I need to encode & in URLs inside HTML?

Yes. URL query separators (e.g., ?a=1&b=2) must be encoded as ?a=1&b=2 when placed in HTML attributes like href. This is one of the most common HTML validation errors.

What happens if I do not encode &?

If followed by text that resembles an entity name (e.g., ©), the browser may render a copyright symbol instead of "©". If followed by unknown text, modern browsers display it as-is but the HTML is technically invalid.

Built by Michael Lip. 100% client-side — no data leaves your browser.