Sams Teach Yourself HTML and CSS in 24 Hours (7th Edition)

Most fonts now include special characters for European languages, such as the accented é in Café. There are also a few mathematical symbols and special punctuation marks such as the circular • bullet.

You can insert these special characters at any point in an HTML document by looking up the appropriate codes in Table 5.2. You'll find an even more extensive list of codes for multiple character sets online at http://www.webstandards.org/learn/reference/named_entities.html.

Table 5.2. Commonly Used English Language Special Characters

Character

Numeric Code

Code Name

Description

"

"

"

Quotation mark

&

&

&

Ampersand

<

&#60;

&lt;

Less than

>

&#62;

&gt;

Greater than

¢

&#162;

&cent;

Cent sign

£

&#163;

&pound;

Pound sterling

|

&#166;

&brvbar;or &brkbar;

Broken vertical bar

§

&#167;

&sect;

Section sign

©

&#169;

&copy;

Copyright

®

&#174;

&reg;

Registered trademark

°

&#176;

&deg;

Degree sign

±

&#177;

&plusmn;

Plus or minus

2

&#178;

&sup2;

Superscript two

3

&#179;

&sup3;

Superscript three

.

&#183;

&middot;

Middle dot

1

&#185;

&sup1;

Superscript one

¼

&#188;

&frac14;

Fraction one-fourth

½

&#189;

&frac12;

Fraction one-half

¾

&#190;

&frac34;

Fraction three-fourths

Æ

&#198;

&AElig;

Capital AE ligature

æ

&#230;

&aelig;

Small ae ligature

É

&#201;

&Eacute;

Accented capital E

é

&#233;

&eacute;

Accented small e

x

&#215;

&times;

Multiplication sign

÷

&#247;

&divide;

Division sign

For example, the word café would look like this:

caf&#233;

HTML/XHTML uses a special code known as a character entity to represent special characters such as © and ®. Character entities are always specified starting with a & and ending with a ;. Table 5.2 lists the most commonly used character entities, although HTML supports many more.

Did you Know?

Looking for the copyright © and registered trademark ® symbols? The codes you need are &copy; and &reg; respectively.

To create an unregistered trademark TM symbol, use <sup>tm</sup>, or <small><sup>tm</sup></small> for a smaller version.

Although you can specify character entities by number, each symbol also has a mnemonic name that is often easier to remember. Here is another way to write café:

caf&eacute;

Notice that there are also codes for the angle brackets, quotation, and ampersand in Table 5.2. You need to use the codes if you want these symbols to appear on your pages; otherwise, the web browser interprets them as HTML commands.

In Listing 5.7 and Figure 5.8, several of the symbols from Table 5.2 are shown in use.

Listing 5.7. Special Character Codes

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Punctuation Lines</title> </head> <body> <p> Q: What should you do when a British banker picks a fight with you?<br /> A: &pound; some &cent;&cent; into him. <hr /> Q: What do you call it when a judge takes part of a law off the books?<br /> A: &sect; violence. <hr /> Q: What did the football coach get from the locker room vending machine in the middle of the game?<br /> A: A &frac14; back at &frac12; time. <hr /> Q: How hot did it get when the police detective interrogated the mathematician?<br /> A: x&sup3;&deg; <hr /> Q: What does a punctilious plagiarist do?<br /> A: &copy; <hr /> </p> </body> </html>

Figure 5.8. This is how the HTML page in Listing 5.7 will look in most web browsers.

Категории