pacerier — 2010-10-19T11:27:09-04:00 — #1
Heys all, is it true that the doctype declaration must be on the very first line (there mustn't even be a blank line above it) in order for it to be "working correctly" ?
pacerier — 2010-10-20T10:35:32-04:00 — #2
The doctype declaration should be the very first thing in an HTML document, before the <html> tag.
The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.
The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers can render the content correctly.
does it mean that it can be at the second or third line and does not necessary have to be the very first line?
scallioxtx — 2010-10-20T11:41:17-04:00 — #3
As far as I know you can put as many blank lines before it as you want.
The question is, why would you want to?
mrhoo — 2010-10-19T14:03:06-04:00 — #4
pacerier — 2010-10-20T17:27:15-04:00 — #5
oh no, i just want to be sure that having blank spaces/lines before doctype would be acceptable.
sholing — 2010-10-27T01:21:21-04:00 — #6
I feel there should not be any blank spaces/lines before the doctype. I never tried with this.
stomme_poes — 2010-10-27T05:02:36-04:00 — #7
Sorry but that W3schools page is full of it. As usual.
Browsers do NOT check to see what kind of markup you're using. They use the MIME type (sent by your server) to determine if the page is plain text, html, or something else. IE including 9 do not understand the application xhtml+xml MIME type. If you are sending "XHTML" doctyped pages to a browser but are setting text/html as your MIME-type, the browser will consider your page as HTML with errors (closing slashes etc will be ignored as errors). IE will ask you if you want to open the document in something else, like another browser or whatever application you've got running.
Browsers do NOT read the DTD. This is why <!doctype html> works all the way back to IE5. However, sending only the first line of the doctype without the reference url WILL put IE into Quirks Mode and possibly the Almost-Standards modes other browsers have... only because they consider it an incomplete doctype. The DTD is for you and the validator.
If you do not want various versions of IE6 to go into Quirks Mode, set your doctype to char1 line1. IE7 I'm not so sure— IE7 has the <?xml?> prologue bug fixed (does not send IE7 into Quirks Mode) but ordinary comments before the doctype can still put IE7 into Quirks Mode.
As far as I'm concerned, if your back-end language is throwing whitespace and newlines before the doctype, consider it the first place to check if you are getting strange errors in IE.
pacerier — 2010-10-27T11:55:47-04:00 — #8
ok so basically the problem is IE6 and possible IE7? the other browsers would not suffer any problems if there are white spaces or not before the doctype declaration right?
stomme_poes — 2010-10-28T04:47:07-04:00 — #9
So far as I know, this is specifically an IE problem... because of Microsoft's decision to use the absence/presence of a doctype for "doctype switching"... where older sites without doctypes are rendered the way they were meant back in the 90's, while sites with a doctype are assumed to be created in this millenium and therefore get "Standards" rendering. (that's "standards" with quotes around it of course... this is Microsoft we're talking about...)
Most other browsers seem to have a not-quite-standards rendering mode for no doctype at all, but I haven't seen anything caused by whitespace/newlines there... even the excessive whitespace and newlines caused by sites outputted by JSP.