HTML Ampersand Code

This page contains HTML code for adding an ampersand within the text of your website or blog.

An ampersand (sometimes referred to as the "and" symbol) is a special character that requires special coding when being used on a website or blog.

To display the ampersand symbol, you can use either the HTML entity number or the entity name.

HTML Entity Number

This example uses the HTML entity number to display the ampersand symbol.

Source CodeResult

HTML Entity Name

This example uses the entity name.

Source CodeResult


Here's an example of the ampersand in action.

Source CodeResult

Those Bang & Olufsen speakers look crazy!

Outputting HTML Code

If you ever need to display HTML code to your users, you will probably find yourself having to use HTML character entities to get it to display correctly in the browser (i.e. without rendering). The ampersand is no exception.

Here's an example of what is required in order to display the code required to output an ampersand symbol. Note that the amp; bit needs to be included twice. Without including it twice, a single ampersand symbol would rendered and that's all.

Source CodeResult

To display the code required to output the & symbol, you need to do this:


Preformatted Content

When using the <pre> tag (which displays content that is preformatted), you can ignore the above advice. The <pre> element renders its contents preformatted exactly as they were entered.

Therefore, you could do the following:

Source CodeResult
Those Bang & Olufsen speakers look crazy!


About the HTML Codes


My Related Sites

Here are some of my other sites: