SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    when to declare doctype?

    hi,

    I use dreamweaver to build site, it always opens a new file with doctype declaration like this

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"

    I know it helps browser to recognize what type of code below it. However I see some sites dont have it at all but they still works terrifically.

    In some scripting language tutorials, the programer dont ever use it at all but, when they save it and run on server, everything is fine.

    So should i need bother to use doctype anymore ?

  2. #2
    SitePoint Evangelist Karpie's Avatar
    Join Date
    Jul 2007
    Location
    Perth, Australia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When to use a DOCTYPE? All the time. There is absolutely no reason not to.

    That some existing may sites work 'terrifically' without it means that a) you're using a modern browser (definitely not IE6 or anything below it) and b) sheer luck.

  3. #3
    SitePoint Wizard bronze trophy Tailslide's Avatar
    Join Date
    Feb 2006
    Location
    Bedford, UK
    Posts
    1,687
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree with Karpie - without a DOCTYPE you end up relying on browsers' error-handling routines which may or may not do what you want them to do.

    Makes life MUCH easier if you always include one (and then code to it).
    Little Blue Plane Web Design
    Blood, Sweat & Rust - A Land Rover restoration project

  4. #4
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Without one the browser uses its original defaults that existed before the standards were developed and so the page will look different in every different browser.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    I know it helps browser to recognize what type of code below it
    Actually I've always been told it doesn't (other than, it puts IE into "almost standards mode" and out of Quirks) and that the browsers actually just look at how the document is sent: text/html. The validator, on the other hand, uses different rules depending on Doctype to know which errors you have (since the errors often have to do with the DTD you're using at the time).

    Unless I'm wrong.

  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    See the HTML FAQ. The answer to question #2 explains what the doctype declaration is and why you should use one.
    Birnam wood is come to Dunsinane

  8. #8
    SitePoint Zealot c.t.c.'s Avatar
    Join Date
    Apr 2007
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Karpie View Post
    When to use a DOCTYPE? All the time. There is absolutely no reason not to.
    I've encountered at least one scenario not to. A doctype declaration tells the browser that the author is coding to a particular standard. If the author isn't, then it's best to omit a doctype declaration.

    I've talked to individuals that have no intention of validating their HTML, nor do they want their page to render in any sort of standards mode (because they don't event know what that means). They also have no intention (at least in the short term) or learning more about these issues. I've recommended that these individuals NOT declare a doctype.

  9. #9
    SitePoint Evangelist Ed Seedhouse's Avatar
    Join Date
    Aug 2006
    Location
    Victoria, B.C. Canada
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by c.t.c. View Post
    I've talked to individuals that have no intention of validating their HTML, nor do they want their page to render in any sort of standards mode (because they don't event know what that means). They also have no intention (at least in the short term) or learning more about these issues. I've recommended that these individuals NOT declare a doctype.
    I on the other hand would recommend that these individuals NOT write web pages.
    Ed Seedhouse

  10. #10
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ed Seedhouse View Post
    I on the other hand would recommend that these individuals NOT write web pages.
    LOL! Exactly what I thought.
    Birnam wood is come to Dunsinane

  11. #11
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,862
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    LOL! Exactly what I thought.
    Those individuals are NOT writing web pages. If it doesn't have a doctype it isn't a web page - the person who wrote it just thinks it is a web page but they are wrong. This of course doesn't include all those pages written many years ago to the HTML 2 standard when the doctype was actually optional.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  12. #12
    SitePoint Enthusiast
    Join Date
    Oct 2008
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by runrunforest View Post
    hi,

    I use dreamweaver to build site, it always opens a new file with doctype declaration like this

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"

    I know it helps browser to recognize what type of code below it. However I see some sites dont have it at all but they still works terrifically.

    In some scripting language tutorials, the programer dont ever use it at all but, when they save it and run on server, everything is fine.

    So should i need bother to use doctype anymore ?
    Ok. New job for you. Go download internet explorer 4 and test their website now. It WILL not work correctly. The doc type is very important in a website. you should ALWAYS have it.

  13. #13
    SitePoint Zealot c.t.c.'s Avatar
    Join Date
    Apr 2007
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Those individuals are NOT writing web pages. If it doesn't have a doctype it isn't a web page - the person who wrote it just thinks it is a web page but they are wrong.
    felgall, this comment is too harsh. Of course anyone that is serious about building the web should always declare a doctype when creating a new document, but there are plenty of people who build the web that are not professionals, nor do they aspire to be. Who cares if John Doe builds a website for his son's baseball team and omits a doctype declaration. I'm sure everyone using and enjoying the site will still refer to it's pages as web pages. Would they be WRONG to use that vocabulary? Picture yourself correcting these parents for using the term web page--it just seems silly. I can't find any definition of the phrase "web page" where a doctype declaration is a requirement. There are so many documents online without doctype declarations. Yes, these are non-standard and certainly not best practice, but they are still web pages.

  14. #14
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    The better phrase would be, they're not writing HTML but they are writing gibberish. That it's just correct enough that browsers' error-handling can do something useful with it is Postel's law coming in-- the browsers being the liberal receivers. The first half of the law is simply not getting fulfilled.

    However this particular topic goes into something else-- is it ok for Joe and Jane to have their own website built with dreambeaver or whatever, without having to spend a year or two learning HTML? I think in general, yes. Family sites, local football group, sure. At some point the computer is just another appliance like the toaster or the automobile and every family has one and can use it enough to get stuff done, including building websites.

    However because browsers are SO good at error handling (they are quite clever sometimes) some of these people stop restricting themselves to the family web site and decide to build sites for friends... they learn more as they go even when they're doing a bunch of stuff wrong, and pretty soon their friends get to know them as "the web guys" and next thing you know they have a "job" on the side for a local business, who's just some mom-n-pop shop who want a purely informational website, don't have time to spend even learning dreambeaver, and cannot afford a professional.

    What eventually happens is two things-- you either get websites like this one, built by a local company who does many many many local websites (and their own photography which possibly is what sets them apart from their competitors), or the guy building sites for friends stumbles across some standardistas or certian web-oriented blogs or possible had a disabled or techie friend who shows another way.

    I would like those who want to build sites to learn there's a working way and a better way, and to decide they're going to bother to do it right if they're going to do it at all.

    Not that I'd be building anything decent if I were completely on my own. I learn too much from many sources that I wouldn't have even stumbled over in my basic surfing.


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
  •