Creating the Foundation
Most Web pages are divided into two sections: the head and the body. The head section is where you define the title of your page, include information about your page for search engines like Google, set the location of your page, add style sheets, and write scripts. Except for the title (see page 64), the content of the head section is not readily visible to the visitor.
To create the head section:
Directly after the opening html tag (see page 60), type <head>.
Leave a few spaces for the contents of the head section.
The body of your (X)HTML document encloses the content of your Web page, that is, the part that your visitors will see, including the text and graphics.
To create the body:
After the final </head> tag, type <body>.
Leave a few spaces for the contents of your Web page (which you'll create with the help of the rest of this book).
Figure 3.3 The head and body elements help you structure your (X)HTML documents.
The head and body tags are required in XHTML. They're optional in HTML but even if you don't physically type them, the browser acts as if they are there and even lets you assign styles to them.
Another reason to use head and body tags is for controlling when a particular script will run (see page 314).
To declare the character encoding:
In the head section of your page, type <meta http-equiv="content-type" content="text/html; charset=encoding" />, where encoding is the character encoding with which you saved the file.
Figure 3.4 I've saved my files in Unicode, with the UTF-8 encoding. (This is BBEdit. For more details about saving files with encodings other than the default for your system, consult Chapter 20, Symbols and Non-English Characters.)
Figure 3.5 When the visitor's browser sees this meta tag, it will know that the page was encoded with UTF-8, and will display it properly. The key is that the encoding that you declare in the meta tag match the one with which you actually saved the file.
Your Web page's character encoding depends on the way you saved it. If you saved it as Text Onlythat is, you didn't choose a special encodingit's a safe bet that your document was saved with the default encoding for your language. For example, the default encoding for English Windows is windows-1252 and for English Macintosh is x-mac-roman.
If you chose a particular encoding upon saving the file, that's the encoding you should use in the meta tag.
You can find a list of common character set codes at http:// www.w3.org/International/O-charset-lang.html.
XHTML requires that you declare the encoding if it is anything other than the default UTF-8 or UTF-16. You can use either the xml declaration (see page 60) or the meta tag described above.
For more about encodings, see Chapter 20, Symbols and Non-English Characters.
Find extra tips, the source code for examples, and more at www.cookwood.com