XHTML Requirements


XHTML, the latest revision of HTML, adds another required element to your Web pages: the <!DOCTYPE> tag. This tag appears at the top of the file and identifies the file as an HTML document conforming to the XHTML requirements. If you were to create an XHTML-conforming document, it would look like the following:

<!DOCTYPE html      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"        xml:lang="en" lang="en"> <head> <title>My XHTML Page</title> </head> <body> <p>This is my first XHTML page.</p> </body> </html>


The <!DOCTYPE> tag has three variations: Strict, Transitional, and Frameset. You declare which one you are using in the top of the file.

  • Strict Declare this variation when you are certain that your viewers will be accessing your pages from newer browsers that interpret style sheets correctly. You'll learn more about style sheets in Lesson 5, "Adding Your Own Style." The Strict variation looks like this:

    <!DOCTYPE html      PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

  • Transitional Declare this variation when you are not certain how your viewers will be accessing your pages.

    <!DOCTYPE html      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-      transitional.dtd">

  • Frameset Declare this variation when you are working in frames. You will learn more about frames in Lesson 10.

    <!DOCTYPE html      PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-      frameset.dtd">

Caution

This book uses the Transitional variation of the <!DOCTYPE> tag throughout. It's a good habit to get into, allowing you to conform to W3C rules, but offering more flexibility that the Strict variation.


You might have noticed one more change from the HTML required elements: The <html> tag has some new attributes: xmlns, xml:lang, and lang. In HTML, you only have to include the <html> tag to identify the document as an HTML file, but XHTML requires that you use the xmlns attribute to link your document to the W3C's definition of XHTML, which continues to evolve. You will learn more about this evolution and how to prepare for it in Lesson 17, "Planning for the Future." For now, just remember to include the <!DOCTYPE> tag and the full <html> tag (shown in the following sample) in all your Web pages. Figure 2.3 demonstrates how the XHTML page, created previously, would appear in the browser.

<!DOCTYPE html      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-      transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"        xml:lang="en" lang="en">


Figure 2.3. Notice that adding the XHTML declaration does not affect your page's appearance.


Caution

The <!DOCTYPE> tag is the only tag that appears in uppercase. All other HTML tags should be lowercase as explained in the next section.




Sams Teach Yourself HTML in 10 Minutes
Sams Teach Yourself HTML in 10 Minutes (4th Edition)
ISBN: 067232878X
EAN: 2147483647
Year: 2004
Pages: 151
Authors: Deidre Hayes

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net