Forum Moderators: open
And how do you choose the best one to use?
I wanted to validate my HTML before submitting my site to DMOZ directory, but the validator (http://validator.w3.org/) says I need a DOCTYPE statement!
Is it true that using the wrong DOCTYPE declaration can cause problems? And if so, is it better not to use one at all?
Thanks,
SkinnyJoe
What version of HTML have you written your site in?
If you have used deprecated styling tags (such as <font> and <center>) then you should probably use the transitional doctype for html4 which is..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
but if you've written clean html and done all your styling with CSS then you'll probably want the strict html4 doctype which is
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
It goes on the very first line of your document (above the <html> tag) and it should all appear on one line.
Is it true that using the wrong DOCTYPE declaration can cause problems? And if so, is it better not to use one at all?
Using a doctype means that browsers know you have written a standards compliant page. As a result your page is more likely to look the same on a selection of different browsers.
If adding a doctype changes the look of your page, then you have been relying on the 'quirks' of that browser.
Using a doctype means that browsers know you have written a standards compliant page.
A doctype doesn't mean that the page is standards compliant, it only indicates which standard you are trying to comply with.
Most importantly, a w3c compliant page will be compatible with future browsers because every new version is stricter and stricter.
By declaring your doctype AND validating, you are not only ensuring that your web site is forward compatible, but that it will perform the same regardless of OS (linux, mac, windows, etc).
[edited by: martinibuster at 6:20 am (utc) on April 12, 2003]
To satisfy the validator, browsers, and spiders, my minimum code on each page begins:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> Your Title Here </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Language" content="EN-GB">
<meta name="Keywords" content=" your, keyword, list, here ">
<meta name="Description" content=" Your Description Here. ">
<meta name="MSSmartTagsPreventParsing" content="TRUE">
</head>
Of the en-gb part, the first two letters come from the code list in ISO 639 and the last two letters come from the code list in ISO 3166.
See also ISO 4217 for codes for representing currency, and then ISO 8601 for formats for date and time.
A doctype doesn't mean that the page is standards compliant, it only indicates which standard you are trying to comply with.
Correct. Apologies, I should have been more precise.
A doctype tells the browser which version of html you have attempted to use. This means the browser can make better decisions about what you were attempting to express with your markup.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
Oh and you should use the FULL doctype, not this one.
The full version includes the address of the DTD (see my first reply). Using the full version puts the browser into standards mode, using the half version keeps the browser in 'quirks' mode.
Content-Language is an HTTP/1.1 feature [w3.org] so older browsers won't support it.
The w3c language task groups says..
Language codes can be (and should be ) used to indicate the language of text in HTML and XML documents. For HTML 4 , language codes are specified with the lang attribute. For XML , language codes are given in the xml:lang attribute. In both cases, language information is inherited along the document hierarchy, i.e.it has to be given only once if the whole document is in one language, and language information nests, i.e. inner attributes overwrite outer attributes.
Maybe doing both is the way to go?
More recent threads on !DOCTYPE:
[webmasterworld.com...]
I have found that modern javascript can lock up older browsers like NetScape Gold. Yeah I do know someone that was still using that up until last week.. they now have Mozilla 1.2.1 and the web is now a whole new experience for them!
.
>> >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> << <<
>> Oh and you should use the FULL doctype, not this one. <<
>> The full version includes the address of the DTD (see my first reply). Using the full version puts the browser into standards mode, using the half version keeps the browser in 'quirks' mode. <<
Using the full version can sometimes cause problems with CSS not working as expected. There are many previous threads with examples of this.
If you write non-standard code, using tag soup, or street HTML, then you are taking a chance as to how that renders in different browsers, or whether it works at all. We all agree that you should avoid doing that.
I prefer to write compliant code that validates and will probably work in all browsers, but I use the short !DOCTYPE and leave the browser in quirks mode. By using the full !DOCTYPE unexpected problems can occur as most browsers are not fully standards compliant yet.
[edited by: g1smd at 6:48 am (utc) on April 13, 2003]
Using the full version can sometimes cause problems with CSS not working as expected.
On the contrary, using the full doctype causes the CSS to work as documented. With the short doctype the browser renders it in quirks mode and emulates all of its historical bugs and non-compliances (for example, the Microsoft IE box model bug)
Whereas the full doctype means that the page will render in a similar manner in most browsers.
[dti.barrysworld.net...]
The style for the main div is as follows:
.testDiv {
width: 400px;
padding-left: 100px;
border: 1px solid #000;
}
...so this div should be 400px(width) + 100px(padding) + 2px(border) = 502px wide.
The first page uses the partial doctype and is rendered in "quirks mode", which seems to use the same box model as IE5 i.e. rendered incorrectly, as the div is shown as 400px wide. For more information on this broken box model and a workaround for IE5, see:
[tantek.com...]
The second page uses the full doctype and is rendered in "standards mode" i.e. correctly.
If you want more information about the box model:
[w3.org...]
Are you talking about newer browsers or old browsers?
Well old browsers have the old bugs in them, regardless of which doctype you use! But using the full doctype means that new browsers will not attempt to emulate these old bugs - which gives you a more consistent display across the various browsers available.