Authoring Webpages/HTML, XHTML and DOCTYPEs

From Wikibooks, open books for an open world
Jump to: navigation, search

An important decision you must make before starting to create a website is the version of (X)HTML that the web pages will conform to.

The following versions of (X)HTML are current in January 2006:

  • HTML 4.01 Strict
    • (HTML 4.01 Transitional)
    • (HTML 4.01 Frameset)
  • XHTML 1.0 Strict
    • (XHMTL 1.0 Transitional)
    • (XHTML 1.0 Frameset)
  • XHTML Basic
  • XHTML 1.1

Versions of HTML prior to 4.0 are obsolete. Web pages in these versions should be withdrawn or converted to a variant of HTML version 4.01 or XHTML. No new page should be created using a version prior to HTML 4.01.

Four versions in the list above are shown in brackets. These versions are intended to be used as stepping stones when converting web pages from obsolete versions to current versions. They are not intended to be used by new web pages.

You shouldn't be using any variant of XHTML 1.0 unless you understand and apply the rules in Appendix C of the XHTML 1.0 specification. You also need to understand the differences between the text/html and application/xhtml+xml MIME types and how to configure your web server to respond with the appropriate MIME type.

Internet Explorer version 7.0 and lower (about 90% of web surfers were using Internet Explorer version 7.0 or lower in January 2006) does not understand XHMTL Basic or XHTML 1.1. These versions should not be used for general purpose web pages at the moment. XHTML Basic is useful for web pages that are only viewed by mobile phones as this is the preferred version for these devices.

This leaves HTML 4.01 Strict as the best choice for new authors. After you have mastered writing quality web pages using HTML you can learn the technical details of serving XHTML properly. (Writing XHTML web pages is just as easy as writing HTML web pages, the problem is configuring the server to serve them properly.)

Note that automatic tools can easily convert valid HTML 4.01 Strict to XHTML 1.0 Strict provided you don't use Javascript in your web pages. Converting Javascript is often a problem since XHTML does not permit document.write(). (If document.write() works in your XHTML then your server is not configured correctly.) If you must use Javascript avoid document.write().

Authors with experience of configuring web servers or access to good technical support may want to use XHTML 1.0 Strict from the start.

Validation[edit]

Regardless of the version of HTML you choose to use it is important that you regularly validate your pages to ensure they conform to your chosen specification.

HTML 4.01 Strict[edit]

The DOCTYPE for HTML 4.01 Strict is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

All HTML 4.01 Strict documents must start with this line (certain variants are permitted but they are beyond the scope of this section).

Many examples of HTML in textbooks will not validate using the Strict DOCTYPE. This normally means that the example uses obsolete HTML elements, e.g. FONT or FRAME. If you find that the examples in a book won't validate (or only validate with the Transitional or Frameset DOCTYPE) the textbook is probably out of date. The content of a significant number of textbooks are five or more years out of date, e.g. some books published in 2005 have content that was cutting edge in 1999 but is no longer considered best practice. Avoid any textbook that contains example that don't validate.


Previous: Adapting a webpage for visual browsers - Up: Table of Contents - Next: Collecting pages in a website