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'?
- Specifying a document type definition
- Transitional documents
- Frameset documents
- Strict documents
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.
- Transitional - XHTML documents that use deprecated elements or attributes.
- Frameset - XHTML documents that use frames (can also include deprecated elements or attributes like the transitional document type).
- Strict - XHTML documents that include no deprecated elements or attributes, and no frames.
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.
In the above example, the line of code that specifies the document type definition is:
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.
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.
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.
