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 Code | Result |
---|---|
& |
HTML Entity Name
This example uses the entity name.
Source Code | Result |
---|---|
& |
Example
Here's an example of the ampersand in action.
Source Code | Result |
---|---|
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 Code | Result |
---|---|
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 Code | Result |
---|---|
Those Bang & Olufsen speakers look crazy! |