SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    must doctype be one the First line?

    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" ?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,904
    Mentioned
    139 Post(s)
    Tagged
    2 Thread(s)
    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?
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh no, i just want to be sure that having blank spaces/lines before doctype would be acceptable.

  6. #6
    SitePoint Member
    Join Date
    Sep 2010
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I feel there should not be any blank spaces/lines before the doctype. I never tried with this.

  7. #7
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    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.

  8. #8
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  9. #9
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •