Sams Teach Yourself HTML, CSS & JavaScript Web Publishing in One Hour a Day

(singke) #1
ptg16476052

Special Characters 141

7


«
© ;


The numbered entities also begin with an ampersand and end with a semicolon, but rather
than a name, they have a pound sign (#) and a number. The numbers correspond to char-
acter positions in the character set for the web page. In this lesson, I’ll assume you’re
using UTF-8. Every character you can type or for which you can use a named entity also
has a numbered entity. Numbered entities look like the following:


à
"
«
©


You can use either numbers or named entities in your HTML file by including them in
the same place that the character they represent would go. So, to place the word résumé
in your HTML file, you would use either


résumé


or


résumé


If you use named entities, the character set is not important because the browser will
translate the named entity into the appropriate character in the character set specified for
the page. You can find a full list of the named entities at


http://www.w3.org/TR/2011/WD-html5-20110113/named-character-references.html


Given that UTF-8 supports more than 100,000 characters, it’s tough to print a table of all
of them. However, one resource you can use to look up UTF-8 characters is the resource
at http://www.utf8-chartable.de/. Remember that you’ll need to use the decimal represen-
tations in your entities.


Character Entities for Reserved Characters


For the most part, character entities exist so that you can include special characters that
aren’t part of the standard ASCII character set. However, there are several exceptions for
the few characters that have special meaning in HTML itself. You must use entities for
these characters, too.


Suppose that you want to include a line of code that looks something like the following
in an HTML file:


if x < 0 do print i

Free download pdf