Southern New Jersey Overlook

head_left_image

DOCTYPE Tag - What Is It's Purpose?

Have you ever looked at the source code of any web page and seen a line at the beginning of the code that starts with "<!DOCTYPE ..."?  If you do your own web design and perhaps use a standard development tool such as Frontpage (now Impression Web) that automatically inserts the line for you, do you know what  it means?   Does it have any effect on how it is handled by browsers (such as Internet  Explorer or Firefox)?  Is it just comments or for use by the development tool?   Does it always have to appear at the top of the page? 

If you look at the source code of enough different web sites, you will see many variations of DOCTYPE.  The purpose of this article is not to teach you how to code web pages or even everything about DOCTYPE, but to help make you aware of it's purpose and the potential effects on how a web page is rendered (interpreted and displayed) by web browsers, then point you in the direction of more in-depth information.

DOCTYPE, which  stands for "document type declaration", is a standard tag that is used to identify to the validating/rendering application, such as a browser, what standards to use in evaluating and displaying the HTML or XHTML properly in your browser.  It must appear as the first line of code, any other non-blank line will cause evaluation to take place in a non-standard, or near-standard, "Quirks" mode in which the browser will assume you are using an old-fashioned (before DOCTYPE came into use) invalid coding -- which can be detrimental to the presentation of your document.

If you are incorporating CSS and XHMTL in your web page, then you must have DOCTYPE properly identified for the browser to correctly handle your page.

There are many variations of a complete DOCTYPE line, here are a few examples you will commonly see:

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

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

The above examples all include a URL (i.e., the "*.dtd" URL, also called the URI, which are files containing the document standard to use for rendering the web page) at the end of the tag, but you will also see DOCTYPE lines without the URL:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

This is allowed.  However, it causes the browser to switch from strict compliance to the standards of a *.dtd file, to a "near-standard" or "Quirks" mode that takes into consideration some of the non-standard behavior of browsers such as Internet Explorer.
 
 
If your web page is not displaying properly and everything else appears correct, you may want to consider whether your DOCTYPE tag is appropriate.  This is especially the case when you are incorporating new features into existing web pages.
 
 
Here are some additional links to help you get a better understanding of the purpose and use of DOCTYPE tags:
Document Types - DTD 
Recommended DTDs to use on web site 
Fix your site with the right document type
HTML 4.01 / XHTML 1.0 Reference   DOCTYPE tag syntax
DOCTYPES and their representative layout mode
DocType Switching and Standards Compliance
!DOCTYPE
!DOCTYPE (according to Microsoft)
O'Reilly - DOCTYPE Explained
Validators: http://www.w3.org/QA/Tools/#validators
Picking A Document Rendering Mode
Rendering Mode and Document Switching
 
 
 
Visit my web site for additional resources and services: LawrenceYerkes.com
  
and visit BestHomes-NJ.com for the latest New Jersey Real Estate property listings (residential, commercial, multi-family, farm, land)

Copyright 2006 by Timon, Inc. All Rights Reserved.

Comments

I've bookmarked your article for later reference. Although I don't understand it all this second, it looks as if it bears closer scrutiny. Thanks for the post!

Posted by Deb Salkeld- - Your Real Estate Virtual Assistant (Diversified Data Solutions, L.L.C.) over 5 years ago

Unless you are editing and posting web pages to a web site, you probably will not need to be overly concerned about this tag as it will be handled for you by the service you are using.

Posted by Lawrence Yerkes - Broker Associate, Southern New Jersey Real Estate Services (RE/MAX Preferred) over 5 years ago
Lawrence, this is true.  In most cases, you should not need to worry about the doctype tag, but it is always best to understand what it is. 
Posted by Matt Wilson (Study Guide Systems) over 5 years ago

This blog does not allow anonymous comments