What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

To display the literal text & in an HTML page, write & in the HTML source. The browser interprets the first & as a character reference, so the page shows &.

What to write in your HTML

Use the following source when you want the rendered page to show the entity spelling rather than just an ampersand:

<p>Write &amp;amp; to show the text &amp;amp;.</p>

Visible result:

Write &amp; to show the text &amp;.

The examples above are shown as code here, so their ampersands are escaped for this article. In your own HTML file, the source line should contain &amp; at each place where you want the page to display &amp;.

Why the extra escaping works

In HTML, an ampersand begins a character reference. The named reference &amp; represents the ampersand character, so writing it directly in HTML displays only &. To show the characters &amp;, escape that leading ampersand as &amp; in the source; the browser displays the first ampersand and treats the remaining letters and semicolon as text.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#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
HTML source Rendered text
&amp; &
&amp;amp; &amp;
&#38;amp; &amp;
&#x26;amp; &amp;

Can you use a numeric character reference?

Yes. HTML supports decimal and hexadecimal numeric character references as well as named references. The ampersand is Unicode U+00026, decimal 38 and hexadecimal 26, so &#38; or &#x26; can supply the initial ampersand. For example, &#38;amp; renders as &amp;. For this simple case, &amp; is usually easier to recognize and read.

Does putting it in code or pre tags change the rule?

No. <code> and <pre> affect presentation; they do not turn off HTML parsing. If you are showing HTML source inside a page, escape its ampersand in the surrounding HTML as needed. For example, to display the source spelling &amp;, the page’s HTML source must contain &amp;amp;.

What about XHTML or XML?

This answer describes HTML syntax. The WHATWG HTML Standard treats HTML and XML as distinct syntaxes; a document served as XHTML/XML follows XML parsing rules, so do not assume every HTML parsing detail applies unchanged. Consult the rules for the actual syntax and serialization you are using.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why the forum workaround may not apply

The original SitePoint question concerned output on a website. Some replies proposed splitting the text with markup for the forum’s own post renderer, but that is specific to how a forum displays posts. For ordinary HTML page text, escaping the leading ampersand as shown above is the direct solution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
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

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.