• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Matt Doyle | Elated Communications

Web and WordPress Development

  • About Me
  • Blog
    • Design & Multimedia
      • Photoshop
      • Paint Shop Pro
      • Video & Audio
    • Online Marketing
      • E-Commerce
      • Social Media
    • Running a Website
      • WordPress
      • Apache
      • UNIX and Linux
      • Using FTP
    • Web Development
      • HTML
      • CSS
      • JavaScript
      • PHP
      • Perl and CGI Scripting
  • Portfolio
  • Contact Me
  • Hire Me
Home / Blog / Web Development / HTML / XHTML / XHTML Document Types

XHTML Document Types

19 November 2007 / Leave a Comment

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: body, img, and so on; and
  • <!ATTLIST ... > declarations; these specify the attributes, such as onclick or 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 <center>, <font>, and 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 <applet>, <isindex>, target, and name.

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 <html> element:


<!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 <center>, <font>, and color — in your markup, as well as deprecated features like <applet>, <isindex>, target, and name.

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: <frameset>, <frame>, and <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 <html> element:


<!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.

Filed Under: XHTML Tagged With: Doctype, DTDs

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

To include a block of code in your comment, surround it with <pre> ... </pre> tags. You can include smaller code snippets inside some normal text by surrounding them with <code> ... </code> tags.

Allowed tags in comments: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre> .

Primary Sidebar

Hire Matt!

Matt Doyle headshot

Need a little help with your website? I have over 20 years of web development experience under my belt. Let’s chat!

Matt Doyle - Codeable Expert Certificate

Hire Me Today

Call Me: +61 2 8006 0622

Stay in Touch!

Subscribe to get a quick email whenever I add new articles, free goodies, or special offers. I won’t spam you.

Subscribe

Recent Posts

  • Make a Rotatable 3D Product Boxshot with Three.js
  • Speed Up Your WordPress Website: 11 Simple Steps to a Faster Site
  • Reboot!
  • Wordfence Tutorial: How to Keep Your WordPress Site Safe from Hackers
  • How to Make Awesome-Looking Images for Your Website

Footer

Contact Matt

  • Email Me
  • Call Me: +61 2 8006 0622

Follow Matt

  • E-mail
  • Facebook
  • GitHub
  • LinkedIn
  • Twitter

Copyright © 1996-2023 Elated Communications. All rights reserved.
Affiliate Disclaimer | Privacy Policy | Terms of Use | Service T&C | Credits