473,969 Members | 5,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The doctype or DTD

drhowarddrfine
7,435 Recognized Expert Expert
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 8566

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

Similar topics

8
4436
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 mode," which IE uses if there is no DocType, then you have to put the proper DocType statement at the top of every page. What is the recommended DocType statement I should use if I am aiming at IE6? Thanks, CMA
6
5176
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, Opera 7.23, Mozilla 1.4 and N.N. 7.1. My site was doing fine until i read i was supposed to keep everything validated so i entered a strict html 4.01 doctype with url following.My HTML validated fine. So i validated my CSS and beside a little...
2
14815
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 display a map. Most of the people doing this will have limited knowledge of HTML. I want to ensure that this page remains an XHTML 1.0 Transitional (or Strict) page, in case some newbie removes the DOCTYPE or some slightly more knowledgeable tries...
25
2746
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 questions about DOCTYPE: 1. Is a doctype statement *required*, or is it just "strongly suggested"? I would probably be using a Transitional doctype. 2. I understand that in a frameset I must use a Framset Doctype ststement,
2
6609
by: PapaRandy | last post by:
Hello, I am trying to validate the following .py webpage as HTML (through W3C). I put: ----------------------------------------------------------------------------- print "Content-type: text/html; charset=utf-8"
24
9196
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. http://javascript.about.com/library/bliebug.htm I was going to use the document.doctype property if I could, but apparently that isn't available unless I use strict. (just tried it with Strict, still doesn't do anything). here's what I've got. anybody got...
6
7893
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
2753
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 seems to function even with eh doctype. But, the floating menu doesn't function once I put a transitional doctype of the page. The js script that handles the floating top of page icon on the
6
7953
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 codebehind, do I need any Doctype or html tags in the page ? Thanks CS
0
10344
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10156
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8449
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
5139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.