6
If you wanted to use the less than sign “<” in normal text on a web page, let’s say you wanted the paragraph:
<p>5 < 10</p>
Then you would have some problems; when the browser sees the character “<” it is expecting a HTML tag (they all start with a < character).
If you did put the above on a web site, it would fail validation (see § 6.9.1), some less lenient browsers may not display it at all. We are breaking the rules.
There are several of these reserved characters in HTML, this is a list:
html reserved characters | ||||
---|---|---|---|---|
The following have special meaning in HTML: |
||||
Less than |
< |
Replacement code: |
< |
|
Greater than |
> |
Replacement code: |
> |
|
Ampersand |
& |
Replacement code: |
& |
|
Double quotation mark |
" |
Replacement code: |
" |
|
Single quotation mark |
' |
Replacement code: |
' |
Now, obviously we want to be able to put quotation marks and ampersands on a web page, they are perfectly normal punctuation marks that get used everywhere.
To get round this problem, we have to use special codes for these characters, if we want to use a less than sign (<) in our text, we have to replace it with <.
This is called an escape sequence, sometimes a symbol code and in my case an &code.
Basically escape sequences are a group of characters that are translated by the browser into a different symbol.
Whenever the browser comes across the sequence of characters <, it will display a straight forward less than sign (<).
So whenever you want to put any of the five characters above in a web page as text to be displayed, use the &code that is given as a substitute.
&codes always start with the ampersand character (&) and end with a semicolon (;).
There are actually a lot more &codes than the five above, they are used to display various common symbols that are not accessible via the keyboard. For example † displays the dagger symbol (†).
The following tables shows all the &codes (escape sequence) characters for HTML.
mathematical | html | code | mathematical | html | code | |||
---|---|---|---|---|---|---|---|---|
× | Multiplication sign | × | × | ∩ | Intersection | ∩ | ∩ | |
÷ | Division sign | ÷ | ÷ | ∫ | Integral | ∫ | ∫ | |
− | Minus sign | − | − | ≈ | Almost equal to | ≈ | ≈ | |
± | Plus/minus sign | ± | ± | ≠ | Not equal to | ≠ | ≠ | |
⁄ | Fraction slash | ⁄ | ⁄ | ≡ | Identical to | ≡ | ≡ | |
∏ | N-array product | ∏ | ∏ | < | Less than | < | < | |
∑ | N-array summation | ∑ | ∑ | > | Greater than | > | > | |
√ | Square root | √ | √ | ≤ | Less than or equal to | ≤ | ≤ | |
∞ | Infinity | ∞ | ∞ | ≥ | Greater than or equal to | ≥ | ≥ | |
html reserved | html | code | html reserved | html | code | |||
< | Less than | < | < | " | Quotation mark | " | " | |
> | Greater than | > | > | ' | Single quote | ' | ' | |
& | Ampersand | & | & | |||||
miscellaneous | html | code | miscellaneous | html | code | |||
← | Leftwards arrow | ← | ← | ¦ | Broken vertical bar | ¦ | ¦ | |
↑ | Upwards arrow | ↑ | ↑ | ° | Degree sign | ° | ° | |
→ | Rightwards arrow | → | → | · | Middle dot | · | · | |
↓ | Downwards arrow | ↓ | ↓ | • | Bullet | • | • | |
↔ | Left right arrow | ↔ | ↔ | |||||
spacing | html | code | currency | html | code | |||
En space |   |   | ¢ | Cent sign | ¢ | ¢ | ||
Em space |   |   | £ | Pound sign | £ | £ | ||
Non-breaking space | |   | € | Euro sign | € | € | ||
numbers | html | code | numbers | html | code | |||
¹ | Superscript one | ¹ | ¹ | ½ | Fraction one half | ½ | ½ | |
² | Superscript two | ² | ² | ¼ | Fraction one quarter | ¼ | ¼ | |
³ | Superscript three | ³ | ³ | ¾ | Fraction three quarters | ¾ | ¾ | |
punctuation | html | code | punctuation | html | code | |||
¡ | Inverted exclamation mark | ¡ | ¡ | … | Horizontal ellipsis | … | … | |
¿ | Inverted question mark | ¿ | ¿ | ‾ | Overline | ‾ | ‾ | |
“ | Left double quote | “ | “ | § | Section sign | § | § | |
” | Right double quote | ” | ” | ¶ | Paragraph sign | ¶ | ¶ | |
„ | Double low-9 quote | „ | „ | © | Copyright sign | © | © | |
‘ | Left single quote | ‘ | ‘ | ® | Registered trademark sign | ® | ® | |
’ | Right single quote | & rsquo; | ’ | ™ | Trademark sign | ™ | ™ | |
‚ | Single low-9 quote | ‚ | ‚ | ¬ | Not sign | ¬ | ¬ | |
◊ | Lozenge | ◊ | ◊ | µ | Micro sign | µ | µ | |
« | Left double angle quote | « | « | ‰ | Per mille sign | ‰ | ‰ | |
» | Right double angle quote | » | » | ′ | Prime (straight quote) | ′ | ′ | |
‹ | Single left angle quote | ‹ | ‹ | ″ | Double prime (straight quote) | ″ | ″ | |
› | Single right angle quote | › | › | † | Dagger | † | † | |
– | En dash | – | – | ‡ | Double dagger | ‡ | ‡ | |
— | Em dash | — | — | |||||
greek small letters | html | code | greek capital letters | html | code | |||
α | Alpha | &alpha | α | Α | Alpha | &Alpha | Α | |
β | Beta | β | β | Β | Beta | Β | Β | |
γ | Gamma | γ | γ | Γ | Gamma | Γ | Γ | |
δ | Delta | δ | δ | Δ | Delta | Δ | Δ | |
ε | Epsilon | ε | ε | Ε | Epsilon | Ε | Ε | |
ζ | Zeta | ζ | ζ | Ζ | Zeta | Ζ | Ζ | |
η | Eta | η | η | Η | Eta | Η | Η | |
θ | Theta | θ | θ | Θ | Theta | Θ | Θ | |
ι | Iota | ι | ι | Ι | Iota | Ι | Ι | |
κ | Kappa | κ | κ | Κ | Kappa | Κ | Κ | |
λ | Lambda | λ | λ | Λ | Lambda | Λ | Λ | |
μ | Mu | μ | μ | Μ | Mu | Μ | Μ | |
ν | Nu | ν | ν | Ν | Nu | Ν | Ν | |
ξ | Xi | ξ | ξ | Ξ | Xi | Ξ | Ξ | |
ο | Omicron | ο | ο | Ο | Omicron | Ο | Ο | |
π | Pi | π | π | Π | Pi | Π | Π | |
ρ | Rho | ρ | ρ | Ρ | Rho | Ρ | Ρ | |
ς | Sigma 1 | ς | ς | Σ | Sigma | Σ | Σ | |
σ | Sigma 2 | σ | σ | |||||
τ | Tau | τ | τ | Τ | Tau | Τ | Τ | |
υ | Upsilon | υ | υ | Υ | Upsilon | Υ | Υ | |
φ | Phi | φ | φ | Φ | Phi | Φ | Φ | |
χ | Chi | χ | χ | Χ | Chi | Χ | Χ | |
ψ | Psi | ψ | ψ | Ψ | Psi | Ψ | Ψ | |
ω | Omega | ω | ω | Ω | Omega | Ω | Ω | |
Table 6.4 HTML character codes |
The above table lists all the common &codes (there are a load more for accents and funny letters), a full list can be found here.
In HTML, any character can be entered by using its character code (given in the &#) and finished with a semicolon (;).
columns of the above tables). HTML character codes are preceded by the ampersand and hash characters (The character codes for all characters are predefined and standard; they are based on the original ASCII character set and then expanded with the use of Unicode characters.
The character code for the letter “A” is 65 (decimal). To enter the letter “A” in HTML using character code, use the following:
A
Character codes can also be entered using hexadecimal notation. I cover hexadecimals in (§ 5.7.1)
The hexadecimal for 65 is 41 and in HTML this would be:
A
To use hexadecimal character codes, the hex number is preceded by &#x.
CSS and JavaScript do not support the &codes of HTML, they do however allow characters to be entered directly with their character code.
To enter a Unicode character directly with its number, simply precede the hexadecimal (it must be hexadecimal) code with a “\” character and enter the hexadecimal code as four digits (use leading zeros if necessary). The following would give the A character:
\0041