Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Write & in HTML source to display a literal ampersand (&). It is a character reference: a sequence that tells the browser which character to render. “HTML entity” is the familiar name for the same idea, though character reference is the more precise term.

What are HTML ampersand codes?

HTML ampersand codes are character references—sequences that begin with an ampersand and represent a character in HTML text or an attribute value. The WHATWG HTML Standard specifies that character references start with U+0026 AMPERSAND (&). The word “entity” is still commonly used; MDN describes it as an older SGML term.

The browser interprets a reference while parsing the HTML. The source spelling and the character shown on the page are therefore different: & in source becomes & in the rendered page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do you write an ampersand in HTML?

Use the named reference & for a literal ampersand. There are also decimal and hexadecimal numeric references for the same Unicode character, U+0026:

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Form HTML source Rendered character
Named & &
Decimal numeric & &
Hexadecimal numeric & &

The named form is easiest to recognize. Numeric forms specify the character’s code point in decimal or hexadecimal and can be useful when you need to refer to a code point directly. For ordinary HTML, choose &.

Why use a character reference?

Some characters overlap with HTML markup syntax. A less-than sign can begin a tag, for example, so writing &lt;p&gt; displays the text <p> rather than starting a paragraph element. The same principle applies to characters such as & that introduce references.

Common references for markup-sensitive characters include:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • &lt; for <
  • &gt; for >
  • &quot; for a double quotation mark (")
  • &apos; for an apostrophe (')
  • &amp; for &

These examples are listed in MDN’s guide to basic HTML syntax.

Does every symbol need an HTML code?

No. In a modern HTML document served with UTF-8 character encoding, you can generally include many symbols directly rather than replacing each with a character reference. References remain useful when a character could be mistaken for markup or when you want to express a character by its named or numeric reference.

Do ampersand codes need a semicolon?

Use the semicolon-terminated spelling when authoring: &amp;, &#38;, or &#x26;. The HTML Standard’s syntax defines named and numeric forms with semicolons, and the named character reference table includes some legacy spellings without one. Those exceptions are not a good pattern for new HTML.

Named references are case-sensitive. Use the exact spelling shown in the standard’s table; for an ampersand, that is lowercase &amp;. Numeric references use digits after &# for decimal or after &#x for hexadecimal.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A literal ampersand followed by text that looks like a reference can be ambiguous to the parser. Encoding the ampersand as &amp; avoids that ambiguity, including in attribute values. The standard’s definition of an ambiguous ampersand covers an ampersand followed by ASCII letters or digits and a semicolon when the sequence is not a recognized named reference.

Best Value
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why does the page show “&amp;” instead of “&”?

If the visible page shows the letters &amp;, rather than a single ampersand, it may be displaying the source text or the text may have been escaped more than once. In normal HTML parsing, one occurrence of &amp; in source renders as &. Check whether the code is inside a code sample or text intended to show HTML source, and whether a template or content system has encoded it again.

Numeric references denote code points, but not every number produces an ordinary printable character. The HTML Standard excludes carriage returns, noncharacters, and control characters other than ASCII whitespace from the allowed numeric references; use numeric forms for known valid characters rather than arbitrary numbers.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.