Which DOCTYPE is better?

PopeCuervoLime's picture

He has: 34 posts

Joined: Oct 2006

Strict or traditional?

I've toyed around with both and I can't find any major differences in either of them. None of my containers get messed up or nothing will look wrong in the browser, and yet every modern website I see has either a strict or traditional setting at the top of the HTML document.

What are the major differences and should I even care?

He has: 629 posts

Joined: May 2007

I don't think there's a "better" or "worse" DOCTYPE. I see two uses for transitional: One is for existing web sites that are, umm, transitioning from 1990s markup that puts presentational markup in the HTML. Example: text for when the image is missing where the "align" attribute is presentational and could be in the CSS.

The other situation is where non-technical people are allowed to add possibly invalid HTML, such as blog comments.

I think those are the only two cases I would opt for transitional. Otherwise, strict is more likely to work in browsers yet to be born. (I also like that I have to remember fewer tags and attributes!)

One more consideration - if you intend to send your web pages as XHTML (e.g. with a file extension of .xhtml or .xml instead of .htm or .html) they won't work unless they validate as strict.

But Microsoft shows no intention of supporting correctly presented XHTML ... Sad

Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;

He has: 629 posts

Joined: May 2007

Oh. I should have added that omitting the DOCTYPE altogether throws Everyone's Favorite Browser(TM) into what is known as "quirks mode." This makes box sizes smaller than in modern browsers (among many other "quirks").

Cordially, David
--
delete from internet where user_agent="MSIE" and version < 8;

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

Strict is definitely better than transitional. If you are coding a new page definitely use strict. As mentioned above, with transitional doctypes some browsers go into "quirks mode" and you can get unpredictible results. In addition, the validator is (obviously) stricter with the strict doctypes. It's harder to validate but that means you have fewer problems!

As David said, only use transitional when you can't be sure of what's going to be put on the page. Like if you've got some code left over from the 90's, or if someone is updating it who doesn't know HTML. I don't find that blog comments are a problem - if you have a blog you can set up your comment form to disallow HTML. I find with my blog the errors are more likeliy to come from me (most people don't use HTML in their comments anyway).

I also think that it's better to have a page that's strict but invalid than a page that's transitional but valid. Errors always slip in, and I'd rather be using a doctype that tells me what they are rather than letting them pass.

PopeCuervoLime's picture

He has: 34 posts

Joined: Oct 2006

Many thanks to everyone for their help!

greg's picture

He has: 1,581 posts

Joined: Nov 2005

As megan said, strict is harder to get validated. But of course isn't too hard as the W3C validator pretty much tells you where you went wrong and what you need to change.
Transitional is much more relaxed in validation.

I always work to XHTML strict, and now have a good idea of what to do and what not to do. Usually now I only have one or two validation errors, and that's usually from forgetfulness rather than lack of knowledge.
You get used to what you code to.

In XHTML, between the two you may find a lot of errors.
That is if you code your page to be strict and then try to validate it in transitional, you may be shocked to the amount of errors. and vice versa

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.