Welcome to WebmasterWorld Guest from 3.92.92.168

Forum Moderators: open

Message Too Old, No Replies

<DOCTYPE> Essential or not?

     
8:39 pm on Sep 13, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 17, 2002
posts:1189
votes: 6


Are doctype declarations essential on every page? On Static and PHP generated?

Aren't they just there for pernickity validation?

If it's just for that very reason then what if I run a page through a validation tool, get a 100% and then just delete the doctype line?

Or do search engines require this information? Are you penalised if you don't have the line at the start of every page?

10:39 pm on Sept 13, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 26, 2004
posts:1497
votes: 0


a) if you validate your page with a doctype then delete the doctype then the page is no longer valid

b) removing the doctype will kick browsers into quirks mode and cause you no end of trouble long term.

Have you got a reason for wanting to leave it out?

12:40 am on Sept 14, 2005 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member encyclo is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 31, 2003
posts:9074
votes: 6


Search engines do not care the slightest about the presence or absence of a doctype - however, parsing (and ranking) can be adversely affected by some markup errors, which is why it is important to validate your pages.

After that, is it essential? The answer is probably no, it is not essential, however it is certainly good practice to have one. As Robin_reala has said, the main role for a "full" doctype, apart from for validation, is to trigger standards-compliance mode [webmasterworld.com] in modern browsers. Removal of the doctype in these circumstances is a bad idea because the rendering mode in the browser would be changed, and it could have negative consequences for the layout.

9:22 am on Sept 14, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 17, 2002
posts:1189
votes: 6


The only reason I have is that some of the coded php pages just output <htm><body>.. etc.

It's only the old static pages which I had created with the html package which sets a doctype at the start of everypage.

I guess I can just cut and paste the static files doctype into the php pages and all will be fine.

It just seems a waste to me. Why bother having a doctype if a) your pages have been tested and validated fine, b) SE's and browsers don't check for it. c) All pages load without any physical errors anyway!

Let's say you guys convince me it's a good idea to have the code. Is one set of string better than the other? Is it possible to use doctype to tweak a page such that browsers load the page faster, or make SE's more efficient?

9:26 am on Sept 14, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Nov 18, 2003
posts:202
votes: 0


I find the question rather peculiar.

How hard is it to put a DOCTYPE on every page? I mean, it's not something that most people know by heart, but one can be copied from the web in less than 20 seconds.

Without a DOCTYPE, of course, your page isn't actually HTML, but you shouldn't let that stop you. The same could be said for header elements -- I mean, if the user doesn't see the <h1> and <h2> elements, then what's the point? You might as well replace them with <font> elements instead.

For that matter, is there actually any point in validating your page at all? I mean, all browsers have a bit of error correction built in. Any one of the popular browsers can cope quite happily with interleving blocks, and will mostly guess what you intended in any case.

11:07 am on Sept 14, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 17, 2002
posts:1189
votes: 6


You may say that it only takes 20 seconds to copy but if I have hundreds of pages it's a lot of time.

I'm just being lazy but it's a valid reason for being lazy if there is no good reason for having a doctype.

Just scanning a few sites out there:

Google doesn't have a doctype but Yahoo does.

Some major sites in my sector don't have a doctype but others do.

There doesn't seem to be any consistency here.

Not only that but some of the sites have:

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

Whilst others have 4.0

Is it the case that some webmasters have it in grained that their sites are not perfect if they don't have a doctype?

11:30 am on Sept 14, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 4, 2004
posts:388
votes: 0


Google doesn't have a doctype

Google's code is optimised to be tiny. The code on their homepage is as small as it could possibly be whilst still working with pretty well every browser ever created.

Considering that they are getting hit *billions* of times per month, and that a single extra character therefore means extra gigabytes of bandwidth, a 120 or so byte DOCTYPE just doesn't look like such a great idea from a business perspective :-)

12:08 pm on Sept 14, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 26, 2004
posts:1497
votes: 0


If you're not having problems now and it's going to cost you time and effort to retrofit then I'd say don't bother. However if you carry on building sites without it then you're wasting time and effort in cross browser compatibility long-term.
2:18 pm on Sept 14, 2005 (gmt 0)

Full Member

10+ Year Member

joined:July 30, 2003
posts:322
votes: 0


b) SE's and browsers don't check for it. c) All pages load without any physical errors anyway!

Not true, many browsers use the DocType to determent whether to render in quirks-mode or standards-mode. This can have dramatic impact how the browser interprets the HTML and CSS on your webpages, epically when you are using the box-model. Remember, we have more browsers to deal with then just IE. If a browser does not interpret these HTML and CSS properties the way you expected it to, then it is a "physical error" no matter who you try to slice it. A "physical error" which the correct DocType can fix.

You may say that it only takes 20 seconds to copy but if I have hundreds of pages it's a lot of time.

I'm just being lazy but it's a valid reason for being lazy if there is no good reason for having a doctype.


Plenty of good reasons have been sited already. But if you have hundreds of webpages to correct, then you should probably look at creating a utility that will concatenate the DocType to the very beginning of every HTML file.

Just scanning a few sites out there:

Google doesn't have a doctype but Yahoo does.

Some major sites in my sector don't have a doctype but others do.

There doesn't seem to be any consistency here.


There are a myriad of reasons for this, not the least of which is that the webdevelopers who created those pages often didn't know any better. But just because some webdevelopers practice bad coding habits doesn't excuse you from following suit.