Basic (X)HTML Structure
This chapter covers the most basic (X)HTML elements—the ones you need to create the structure of your document. You'll learn how to create new paragraphs, headers, page breaks, comments, and more.
Creating a clear and consistent structure makes it that much easier to apply styles to your document.
Starting Your Web Page
Begin your page by using a DOCTYPE (see page 40) to declare what type of HTML or XHTML you're using. The DOCTYPE lets browsers know what to expect and tells validators how to judge your code in order to check its syntax. Then, signal the beginning of the actual code with the opening html tag.
Figure 3.1 Here's the DOCTYPE for a transitional HTML document as well as the opening and closing html tags. It's a gruesome bit of text. I recommend just copying it from one document to the next instead of trying to type all that gobbledy-gook.
To start a transitional HTML 4 page:
- Type <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> to declare that you're using transitional HTML 4.01 in your Web page.
- Type <html> to begin the actual HTML portion of your document.
- Leave a few spaces for creating the rest of your page (using the rest of this book).
- Type </html>.
To begin a transitional XHTML page:
- Type <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> to declare that you're using transitional XHTML in your Web page.
- Type <html xmlns="http://www.w3.org/1999/xhtml"> to begin the XHTML portion of your page and declare its namespace.
- Leave a few spaces for creating the rest of your page (using the rest of this book).
- Type </html>.
Figure 3.2 Here's the DOCTYPE for a transitional XHTML document, the opening html tag and required namespace declaration, and the closing html tag.