| Understanding the Basic Document Structure | | Print | |
As you saw in Chapter 1, XHTML documents are contained between the opening <html> and closing
</html> tags (this <html> element is also known as the root element). Inside these tags, the document is
split into two sections:
❑ The <head> element, which contains information about the document (such as a title or a link to a
style sheet)
❑ The <body> element, which contains the real content of the document that you see.
This section takes a closer look at the four main elements that form the basic structure of every document:
<html>, <head>, <title>, and <body>. These four elements should appear in every XHTML
document that you write, and you will see them referred to throughout this book as the skeleton of the
document.
Remember that before an opening <html> tag, an XHTML document can contain the optional XML
declaration, and it should always contain a DOCTYPE declaration indicating which version of XHTML it
uses.
The <html> Element
The <html> element is the containing element for the whole HTML or XHTML document. After the
optional XML declaration and required DOCTYPE declaration, each XHTML document should have an
opening <html> tag and each document should end with a closing </html> tag.
If you are writing Strict XHTML 1.0, the opening tag must also include something known as a namespace
identifier (this indicates that the markup in the document belongs to the XHTML 1.0 namespace).
Therefore the opening tag should look like this:
<html xmlns="http://www.w3.org/1999/xhtml">
While it is not strictly required in Transitional XHTML documents, it is a good practice to use it on all
XHTML documents.
Only two elements appear as direct children of an <html> element: <head> and <body> (although the
<head> and <body> elements will usually contain many more elements).
The <html> element can also carry the following attributes, which you will meet in the “Attribute
Groups” section later in this chapter:
id dir lang xml:lang
You may sometimes come across the use of the version attribute in HTML 4.1 and earlier to indicate
which version of HTML the document uses, although it is usually left off. XHTML documents should use
the DOCTYPE declaration along with the xmlns attribute instead to indicate which version of XHTML
they use.
The <head> Element
The <head> element is just a container for all other header elements. It should be the first thing to appear
after the opening <html> tag.
Each <head> element should contain a <title> element indicating the title of the document, although it
may also contain any combination of the following elements, in any order:
❑ <base>, which you will meet in Chapter 3.
❑ <object>, which is designed to include images, JavaScript objects, Flash animations, MP3 files,
QuickTime movies and other components of a page. It is covered in Chapter 4.
❑ <link> to link to an external file, such as a style sheet or JavaScript file, as you will see in
Chapter 9.
❑ <style> to include CSS rules inside the document; it’s covered in Chapter 9.
❑ <script> for including script in the document, which you see in Chapter 14.
❑ <meta>, which includes information about the document such as keywords and a description,
which are particularly helpful for search applications; this is covered in Chapter 16.
The opening <head> tag can carry the following attributes:
id dir lang xml:lang profile
The profile attribute is not actually in use yet, although it was included so it could be used in the future
to specify a URL for something known as a profile that would describe the content of the document. The
other attributes are covered in the “Attribute Groups” section later in this chapter.
The <title> Element
You should specify a title for every page that you write inside the <title> element (which is a child of
the <head> element). It is used in several ways:
❑ At the very top of a browser window (as shown in Figure 2-1)
❑ As the default name for a bookmark in browsers such as IE and Netscape
❑ By search engines that use its content to help index pages
Therefore it is important to use a title that really describes the content of your site. For example, if you
have a “contact us” page in your site, do not just use Contact Us for the title. Include your company or
site name. Something like this would be more appropriate:
<title>Wrox Music: Contact Details</title>
Where possible, your title should describe the content of that page; for example, your home page should
not just say “Home page.” It should say what your site is about. For example:
<title>Wrox Music: Vintage Guitars, Keyboards, and Drums</title>
The test for a good title is whether a visitor can tell what she will find on that page just by reading the
title, without looking at the actual content of the page.
The <title> element should contain only the text for the title; it may not contain any other elements.
For example, you cannot add any instructions as to how the title should be formatted. Figure 2-1 shows
how the content of the <title> element is displayed in the browser window and in the favorites in IE.
(This example is taken from the code you can download for this chapter, and is the index.html file in
the Chapter 2 code folder.)
The <title> element can carry the following attributes, which are covered in the “Attribute Groups”
section later in the chapter:
id dir lang xml:lang
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment.
| Users' Comments (0) |
|
No comment posted





