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

(singke) #1
ptg16476052

Special Characters 139

7


Character Encoding


Before I can talk about how to add special characters to your web page, I first have to
talk a little bit about character encoding. When we think of text, we think of charac-
ters like “a” or “6” or “&” or a space. Computers, however, think of them as numbered
entries in a list. Each of these lists of characters is referred to as a character set.


One character set you may have heard of is ASCII, which contains 128 characters,
including the upper and lowercase letters, numbers, punctuation, and a number of other
special characters like space, carriage return, and tab. The space character is in the 32nd
position of the list of ASCII characters. When you convert that to hexadecimal (base 16)
notation, it’s in position 20. That may ring a bell—back in Lesson 6, you learned that
when URL encoding is used, spaces are encoded as %20. That’s because encoded charac-
ters in URL encoded are numbered by their position in the list of ASCII characters.


When a web page is displayed, the browser looks up all of the characters on the page
in the character set that is being used to display the page. There are a number of ways
to specify which character set is used for a page. If none of them are used, the browser
displays the page using its default encoding. There are a whole lot of character sets avail-
able; you can see a list of them from Chrome’s View Encoding menu in Figure 7.11.


For the most part, as long as you stick with using characters from the list of 128 charac-
ters in the ASCII character set, your page will look fine regardless of which encoding is
selected because all the characters are based on ASCII. You run into problems when you
get past those 128 initial characters. This becomes important if you want to use special
characters like em dashes, smart quotation marks, or letters with accents.


There is a lot more that can be said about character encoding; in fact, large books have
been written on the topic. At this point, I’m just going to give you a shortcut. To ensure
that your special characters always look the way they’re supposed to, you just have to


FIGURE 7.11
A list of some
of the character
encodings sup-
ported by Google
Chrome.
Free download pdf