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.
HTML Entity Name
This example uses the entity name.
Here’s an example of the ampersand in action.
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.
To display the code required to output the & symbol, you need to do this:
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.