XHTML
  1. XHTML intro
  2. XHTML purpose
  3. XHTML/HTML diff
  4. XHTML syntax
  5. XHTML DTD
  6. HTML to XHTML
  7. XHTML validation
  8. XHTML modules
  9. HTML 5
  10. XHTML history
  11. XHTML summary

XHTML document type definition

Not every XHTML document is the same. Each one must be classified in a special way.

This tutorial focuses on:

What is a 'document type definition'?

A Document Type Definition (DTD) is the specification by which XHTML documents are classified.

Each document type definition specifies what type of document an XHTML document will be.

Every XHTML document you create will be one of the above types.

Specifying a document type definition

Now that you know what the three document types are, how do you go about classifying your XHTML documents accordingly?

A document type definition is specified with the <!DOCTYPE> declaration, with each document type including different data for it.

Although a document type definition is technically not required for a functioning webpage (though you must have it if you want your pages to validate with an XHTML validator!), it is good practice to always include it in your code. As you learn to build webpages, get into the habit of always including the document type definition in your code.

An XHTML document consists of three parts - <!DOCTYPE> definition, <head> section
, <body> section.

XHTML document core structure:
<!DOCTYPE .....> <html> <head> ..... </head> <body> ..... </body> </html>
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Specifying a document type definition</title> </head> <body> <h1>Content</h1> </body> </html>

In the above example, the line of code that specifies the document type definition is:

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

The <!DOCTYPE> declaration must be the first line of code in an XHTML document, even before the <html> tag.

Transitional documents

The transitional document type definition specifies an XHTML document that uses some deprecated elements or attributes such as the <font> tag, and can also be used for documents that will be displayed in browsers that do not support CSS.

Transitional document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Transitional document type</title> </head> <body> This is a transitional HTML document </body> </html>

Frameset documents

The frameset document type definition specifies an XHTML document that uses frames to display one or more pages at the same time in the browser window and can also include deprecated elements or attributes (like the transitional document type definition). But unlike the transitional document type definition, the frameset document type definition uses the <frameset> tag instead of the <body> tag.

Frameset document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> <html> <head> <title>Frameset document type</title> </head> <frameset cols="50%, 50%"> <frame src="frame1.html" /> <frame src="frame2.html" /> </frameset> </html>

Strict documents

The Strict document type definition specifies an XHTML document that includes no deprecated elements or attributes such as the <font> tag, and no frames.

Strict document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Strict document type</title> </head> <body> <h1>Content</h1> </body> </html>
© Copyright 2013-2014 Landofcode.com
Terms of use | Privacy policy | Copyright information