473,385 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,385 developers and data experts.

The doctype or DTD

drhowarddrfine
7,435 Expert 4TB
The Doctype or DTD

Many coders get confused by all the talk of doctypes and how they affect browsers and the display of their web pages. This article will get right to the point about doctypes and their use.

Doctype is short for its full name "Document Type Definition", or DTD. If you pay attention to what those words mean, you will notice that it is used in your web page, the document, to define the data types, that is, the elements your page contains. This is where your browser learns what a <div> tag means and what its attributes are. Without defining the types, you are leaving the browser free to decide how to define such things itself and it will do the worst thing possible by assuming "quirks mode".

"Quirks" is the mode older browsers settle into due to an issue with Internet Explorer years ago. The folks at Microsoft misinterpreted the W3C web standards in several ways. For example, while all other browser makers understood that margin and padding spacing fell outside the boundaries of a containing element, Microsoft made Internet Explorer put the padding on the inside. Along with other errors, this gave pages written to the standard a "quirky" look in Internet Explorer.

To correct this problem, browsers now look for a proper doctype as the first line of code in every web page. Without it, they assume "quirks" and it's like 1996 all over again. So what does that tell us?

A proper doctype is REQUIRED on each and every web page to guarantee the best adherence to the standard by ALL browsers.

Which Doctype?

There are three: strict, transitional and frameset. Let's look at them individually in reverse order.

Frameset. If you are using frames in your code, this is the one to use.

For HTML:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
  2.    "http://www.w3.org/TR/html4/frameset.dtd">
For XHTML:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
  2.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Transitional. Transitional allows coders to use markup that was written using HTML elements that are deprecated, that is, those tags that are intended to be dropped from the standard and moved into presentational markup (CSS). If you have an older page containing tags like <center> or <font> or other presentational markup, you can use the transitional doctype while you "transition" the markup in the page to modern standards. Other than that, there is NO reason to use the transitional doctype.

For HTML:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2.    "http://www.w3.org/TR/html4/loose.dtd">
For XHTML:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Strict. ALL newly created pages should use the strict doctype. Strict means you are coding to the current standard with current elements and have moved your presentational information to a CSS stylesheet. Since all new pages should use strict, you can, essentially, forget about the others because they serve no purpose.

For HTML:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2.    "http://www.w3.org/TR/html4/strict.dtd">
For XHTML:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
By using the correct doctype, the W3C Validator can also warn you of errors in your code before you get too far along. You should always test your pages in as many browsers as you can but one that is modern and standards compliant is best. Firefox and Opera are especially helpful in checking compliant code.

Warning: some browsers, IE specifically, look for the doctype on the very first line of the markup. If any characters of any kind preceed the doctype itself, the browser assumes no doctype is present and goes into quirks mode.

The XML Declaration

In you are reading about XHTML, you will come across this line before the doctypes listed above: <?xml version="1.0" encoding="utf-8"?> . This is a XML "Processing Instruction" or PI. XHTML is, after all, XML formulated as HTML so your page can use HTML elements. But it is XML so it must be declared as such.

Unfortunately, Internet Explorer less than version 7 will stumble on this and go into quirks mode for the same reasons mentioned above. So it is best to just leave this line out for now. Chances are you are serving your page as text/html and declaring XHTML isn't gaining you any benefit anyway. If you are serving XHTML as text/xml+xhtml then you know you are serving browsers that can handle XHTML natively. Then the XML Declaration should be included on the first line. Be aware, though, that Internet Explorer does not handle native XHTML.
Jan 23 '07 #1
0 8511

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: CMAR | last post by:
I create my website using Front Page 2000. I notice that none of my pages have a DocType statement at the top. I have read that if you want IE6 to use "Standards mode" rather than the "Quirks...
6
by: Patrick | last post by:
Hi I am fairly new to CSS and the web.I am trying to build a site more to practice my skills than for the site itself. I have been focusing on CSS and try my best to make it work in I.E 6.0,...
2
by: DartmanX | last post by:
I doubt this is possible, but I want to ask, just in case it is. I have a project going using Google Maps. This project spits out an HTML page template for people to post to their website and...
25
by: Viken Karaguesian | last post by:
Hello all, I'm somewhat of a newbie to webscripting. I've made a couple of websites in the past with WYSIWYG software, but now I'm much more interested in manual scripting. I have some...
2
by: PapaRandy | last post by:
Hello, I am trying to validate the following .py webpage as HTML (through W3C). I put: ----------------------------------------------------------------------------- print "Content-type:...
24
by: Jim Michaels | last post by:
I can't get any "universal" code working that tries to detect whether the document it's in is xhtml or html. I found this, which tells me I have a hill to climb with no equipment....
6
by: Rolf Welskes | last post by:
Hello, if I have for example: <table style="width: 100%; height: 100%;" border="1"> <tr> <td style="width: 100px">k </td> <td style="width: 100px">k </td> </tr>
11
by: rfr | last post by:
When I add a transitional doctype to the weather page on my community website, I loose certain Js scripts, but not all of them. This puzzles me. The main menu is powered by a js script and...
6
by: WT | last post by:
Hello, I am searching for a way to generate automatically from codebehind the <!Doctype....for asp.net pages using .net 3.5 c# and vs2008. Subidiary question: if I do a server transfert in my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.