1. Computing

Discuss in my forum

Anatomy of a DOCTYPE

An Explanation of the DOCTYPE Identifier

By

A typical DOCTYPE you might see on an HTML document is the HTML 4.01 transitional DOCTYPE. The DOCTYPE for HTML 4.01 Transitional documents looks like this:

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

The DOCTYPE isn't exactly an HTML tag or XHTML element. Instead it is a declaration and always appears at the very top of your documents.

Parts of a DOCTYPE

A DOCTYPE is made up of the following parts:

  • !DOCTYPE
    The identifier. It indicates to the user-agent that the enclosed information will define the type of document of the page.
  • HTML
    The Top Element. This tells the browser what element to expect as the top-level element. For HTML and XHTML documents this element would be <html>
  • PUBLIC
    The Availability. The most common DOCTYPES you will use will be publicly available - "PUBLIC". But you can also specify a local DTD with the "SYSTEM" key word.
  • "-//W3C//DTD HTML 4.01 Transitional//EN"
    The Formal Public Identifier. This entire string is what identifies the DOCTYPE.

The FPI is made up of these parts:

  • -
    Registration. If there is a plus-sign (+) here, that means that the organization is registered with the ISO. A minus-sign (-) indicates that it is not registered.
  • W3C
    The Organization. This is the group that owns and maintains the DOCTYPE being used.
  • DTD
    The Type. This defines the type of DOCTYPE used.
  • HTML 4.01 Transitional
    The Human-Readable Label. This is the label that tells you what DTD is being used. It is written so that humans, rather than computers, can understand it.
  • EN
    The Language. This is the language that the DTD is written in. It is not the language of the content of the page.

The rest of the DOCTYPE identifier is optional:

  • "http://www.w3.org/TR/html4/loose.dtd"
    The URI. This is an optional URL indicating where the DTD for this DOCTYPE can be found.

Sample HTML DOCTYPES

Here are some of the more common HTML DOCTYPES:

  • HTML 2.0
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0 Level 2//EN">
     <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
     <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML Level 2//EN">
  • HTML 3.0
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN">
  • HTML 3.2
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  • HTML 4.01
    [Strict DTD]
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
     
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     [Frameset DTD]
     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

Sample XHTML DOCTYPES

And here are the common XHTML DOCTYPES:

  • XHTML 1.0
    [Strict DTD]
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
     
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     [Frameset DTD]
     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  • XHTML 1.1
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN">
  • XHTML 2.0
    <DOCTYPE html PUBLIC "-//W3C//DTD XHTML 2.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml2.dtd">
  1. About.com
  2. Computing
  3. Web Design / HTML
  4. XML
  5. DTDs
  6. DOCTYPE Explained - What is a DOCTYPE - XHTML DOCTYPE - HTML DOCTYPE

©2014 About.com. All rights reserved.