1.3 Reserved Charcters
When adding content to a website it is important to know that some keyboard characters are reserved purely for HTML code, one example being the less and greater than signs (< >) used in element tags. Characters such as these cannot be used within your content text (such as paragraphs) because Internet browsers may mistake them for markup code. This could lead to display errors on screen ranging from the sublime to the ridiculous.
However, this does not mean you cannot use these at all, but in order to display these reserved characters safely, character entities have to be inserted instead. There are two formats that can be used for this:
For example, to use the ampresand (or and) symbol within text, either of the following can be used:
<p>Text & more text.</p> <p>Text #35; and more text.</p>
Either of these will render like this in a browser:
Text & more text.
Either format may be used. The entity names are usually easier to remember than the numbers, but cross-browser support is usually better for the entity numbers. There are literally hundreds of codes for such characters, but below are some of the more common characters used in HTML and their entity numbers and names to be used instead (in content):
| Character | Entity Number | Entity Name | Description |
|---|---|---|---|
| " | " | " | quotation mark |
| ' | ' | ' (does not work in IE) | apostrophe |
| & | & | & | ampersand |
| < | < | < | less-than |
| > | > | > | greater-than |
The non-breaking space is also a commonly used character entity. HTML will normally truncate (remove) extra spaces in content text, meaning for example that entering 5 spaces in your text will result in HTML removing 4 of them. In order to add lots of spaces to text, the following character entity can be used as often as is required:
However, for best practice this should be avoided wherever possible in favour of using CSS to achieve the desired effect, but this is for later (see the CSS Tutorial).
Hard to Find Characters
In addition to these reserved characters, there are many entity codes for characters that simply cannot be entered easily using the keyboard as they are simply not shown on the keys. These can be found in the tools section under Character Entities.
ISO-8859-1 is the default character set in most browsers. The first 128 characters are the original ASCII character-set including the numbers 0-9, the uppercase and lowercase English alphabet and some special characters. The higher part (codes from 160-255) contains the characters used in Western European countries and some commonly used special characters.
This is the end of the first section of the HTML Tutorial. Believe it or not but in this section you have learned enough basic HTML to build a very simple website. In the following section you will learn more tags and how to add a little styling to your pages using attributes.