XHTML Document Types
What are document type definitions, and why do you need to know about them when writing XHTML pages? This article reveals all.
In this article you take a look at the concept of document type definitions, or DTDs, and explore the three DTDs available to you when writing XHTML documents.
Understanding document type definitions
Document type definitions are used to describe classes of SGML and XML documents. For example, there is a DTD that describes each version of HTML, from 1.0 up to 4.01, as well as each of the various flavours of XHTML 1.0 (which we look at in this article). A DTD is a set of computer-readable rules that lists what elements and attributes are allowed in a document of that type.
For example, take a look at the DTD for HTML 4.01 Strict. The main bulk of the DTD comprises:
- A bunch of
<!ELEMENT ... >declarations for specifying the list of available elements in HTML:
img, and so on; and
<!ATTLIST ... >declarations; these specify the attributes, such as
style, that are allowed within each element.
Some browsers, such as Internet Explorer, won't show you the contents of the DTD in the browser window; you'll need to save the file and open it using a text editor.
To let Web browsers — and the rest of the world — know which type of document you're creating, you place a document type declaration (or "DOCTYPE") at the top of your page. The document type declaration references one of the publicly available document type definitions (DTDs). For example, the following document type declaration at the top of a Web page indicates that the page should validate to HTML 4.01 Transitional:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The three XHTML DTDs
You can use any one of three document types for your XHTML pages:
- XHTML 1.0 Strict
- XHTML 1.0 Transitional
- XHTML 1.0 Frameset
XHTML 1.0 Strict
The XHTML Strict document type forbids any markup elements and attributes that are used to control presentation, such as
color. The implication, of course, is that you should be using CSS to control all the presentational aspects of the page (which is a good idea, if possible). It also removes various deprecated elements and attributes, such as
XHTML 1.0 Strict is essentially HTML 4.01 Strict reworked as XML.
This document type is the best choice of the three, because it cleanly separates content from presentation. In many ways, it's the "pure" version of XHTML. Future versions of XHTML will be based on XHTML 1.0 Strict.
To create XHTML 1.0 Strict pages, add the following DOCTYPE to the top of each page, before the
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional
XHTML 1.0 Transitional is more forgiving than XHTML 1.0 Strict, because it allows presentational elements and attributes — such as
color — in your markup, as well as deprecated features like
XHTML 1.0 Transitional is basically HTML 4.01 Transitional reworked as XML.
This document type is useful if you want to move an HTML 4.0 Transitional (or earlier) website to XHTML as quickly as possible, since you can retain much of your presentation markup in the page. It's also great for those times when you simply have to use the
target attribute on a link! Ultimately, though, you want to be aiming to convert your pages to XHTML Strict for maximum future-proofing.
To build your pages as XHTML 1.0 Transitional, use this DOCTYPE right at the top of each page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.0 Frameset
The final XHTML document type available to you is XHTML 1.0 Frameset. This is simply XHTML 1.0 Transitional with added elements to support framesets:
<noframes>. It's essentially HTML 4.01 Frameset reworked as XML.
Needless to say, this is the document type to use if you're building a framed website. To use it, add the following to the top of your site pages, before the
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
To summarize: XHTML 1.0 Strict is the best XHTML document type to use, if possible. Use XHTML 1.0 Transitional if you want to retain presentational elements and attributes in your markup, or XHTML 1.0 Frameset if your site uses frames.
Responses to this article
There are no responses yet.
Post a response
Want to add a comment, or ask a question about this article? Post a response.
To post responses you need to be a member. Not a member yet? Signing up is free, easy and only takes a minute. Sign up now.