What's the doctype for?

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

What's the doctype for?

Post by JellyFish »

I'm not asking this in a noob way, but rather a rational way. What purpose does the doctype serve other then specifying what version of html you are using? Why did the standards go this way; with this approach? Why didn't the standards just add a version attribute to the html element?

Code: Select all

 
<html version="5">
  <head>
    ...
  </head>
  <body>
    ...
  </body>
<html>
 
Every new version of html would just require that you change the number in the version attribute. Why did the standard go this way:

Code: Select all

 
<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
  </body>
</html>
 
The doctype for html 5 is so ambiguous. The doctype is html? Which version of html? They over-simplified IMO. It should have been:

Code: Select all

<!DOCTYPE html5>
Other wise, what would html 6's doctype look like? If they just added a number to the doctype, the next version of html would be more consistent:

Code: Select all

<!DOCTYPE html6>
But why even have a doctype? Why not just a version attribute, at least then why would have a/another reason for the html tags being wrapped around the entire document.

So really, what's the rational behind the doctype in the first place? Does anyone here on these forums know? Could anyone tell me?

Thanks for reading.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: What's the doctype for?

Post by jackpf »

I think the doctype should also link to a DTD to validate the page against.

So yeah... that may be why :D
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: What's the doctype for?

Post by JellyFish »

jackpf wrote:I think the doctype should also link to a DTD to validate the page against.

So yeah... that may be why :D
But there is no DTD in HTML5's doctype.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: What's the doctype for?

Post by jackpf »

Oh...I guess it's just XHTML that specifies a DTD then...

I'm not sure then. :oops:
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: What's the doctype for?

Post by JellyFish »

What's a DTD even for? Do things really need to be as complicated as that? I really dislike the fact that I don't have the ability to jot out complete standard (X)HTML from my memory. I think things need to be more simple. Saying the doctype is html when the first element of the document is html is kind of redundant. So really, why not just a version attribute? I guess this is a question for WHATWG.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: What's the doctype for?

Post by jackpf »

Well, you should really have already told the browser what the document is with a content-type header...so it will understand the <doctype>. I always thought the doctype was to specify a DTD to validate the page against...because obviously XHTML is a variation of XML...and XML accepts pretty much any tags, which is why it needs a DTD to be validated against.

I guess maybe HTML doesn't need to be validated against anything...since syntax errors don't really matter.

This is all just hypothetical though. Don't take my word for it :P
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: What's the doctype for?

Post by pickle »

The purpose of specifying a doctype is basically to tell the browser what dialect you're using. Most engines have 2 modes - standards mode and "try to get it to display" mode. If you specify a doctype, the engines go into standards mode & display the page with a specific set of rules. This is usually faster to render, and provides for better cross-browser compatibility.

Imagine you knew you were going to have a conversation with someone who speaks English. There are a lot of accents out there. If you're expecting to talk to someone from your hometown, but hear a really rough Australian accent, it might take a bit of work to understand. If you knew they were going to speak with an Australian accent to begin with, you'd have a better chance of completely understanding them. Browsers are the same way - if you specify which dialect you're using, they'll have a better chance of understanding the document completely.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

Re: What's the doctype for?

Post by wiseguy12851 »

html is moving towards uniform like XML and XHTML therefore the websites who do not use uniform coding like HTML are still being applied uniform-like tags. The doctype is mandatory for XHTML and is required to be followed by a DTD. To make it easier on current browsers and new browsers HTML is uniformed to also include a doctype so programming browser software and updates can be easier and less chance of bugs.

BY THE WAY -------------------

the doctype you included above is incorrect and is suppose to include a DTD

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> --- HTML Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> --- Transitional
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> --- Frameset

As conformed by the W3C
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Re: What's the doctype for?

Post by JellyFish »

wiseguy12851 wrote:html is moving towards uniform like XML and XHTML therefore the websites who do not use uniform coding like HTML are still being applied uniform-like tags. The doctype is mandatory for XHTML and is required to be followed by a DTD. To make it easier on current browsers and new browsers HTML is uniformed to also include a doctype so programming browser software and updates can be easier and less chance of bugs.
What do you mean by uniform; I don't know what you mean by that? :? Could you explain what you mean by uniform and uniform coding, because I'm not familiar with that word in this context? :P
wiseguy12851 wrote: BY THE WAY -------------------

the doctype you included above is incorrect and is suppose to include a DTD

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> --- HTML Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> --- Transitional
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> --- Frameset

As conformed by the W3C
Actually the doctype I was giving was the HTML5 doctype not HTML4. What I'm discussing in this thread, is about the HTML5 doctype. Sense the HTML5 doctype really doesn't say anything more then "HTML", not even "HTML5", it's just saying it's html. Sense it's so ambiguous, why do we even need it? If I were standardizing things, I would simply add a version attribute and be done with it. Why do we need a DTD? Or why would we have to write it out in our code? Why can't it be the browser's job to check against the correct DTD or what ever you do with a DTD?
wiseguy12851
Forum Newbie
Posts: 11
Joined: Sun Aug 23, 2009 9:15 pm

Re: What's the doctype for?

Post by wiseguy12851 »

Uniform can loosely be referenced as "by the book" and similarity. Ideally is would be less catastrophic for browser programming if all pages had similar tags, which in this case is doctype, It would be easier for a programmer to program a web browser to look for a specific tag automatically rather than determine if the page will have it or not thus de-complicate a ton of issues and allow for more sites to safely transition over to advanced coding like advanced CSS without worry on the client end.

so the HTML tag you described above is overlooked by older browsers and greatly aids new browsers, as well as any mid-transitions. XML and XHTML both require it so add it to HTML as well to get uniform and simplicity without breaking backwards compatibility.
Post Reply