/    Sign up×
Community /Pin to ProfileBookmark

doctype – does it matter?

hi,

does it not matter which doctype you use – as long as you use one, to avoid quirks mode and force standards mode? i’ve never seen a rendering difference between the strict,transitional,frameset types, they all show frames correctly (for example). in terms of validation it may be important (search engines) but for display? seems to have no effect in my experience (which is rather limited admittedly)

any thoughts,

thanks!

dean.

to post a comment
HTML

20 Comments(s)

Copy linkTweet thisAlerts:
@scragarJan 08.2008 — mess up on an xhtml page and we'll see how you react(and I mean really serve it as application/xhtml+xml, not this wimpy text/html rubbish.

any errors in an xhtml document = browser throws a paddy and refuses point blank to continue.

except for IE, but that doesn't even try.
Copy linkTweet thisAlerts:
@felgallJan 09.2008 — The doctype defines which language you are using. If you specify one language and then use another in your page then while some browsers will realise your error and fix it, others will not and your page will therefore not necessarily work correctly in all browsers simply because you told the browser the wrong language.
Copy linkTweet thisAlerts:
@dtm32236Jan 09.2008 — transitional allows you to code more 'loosely'... you don't have to follow the standards so closely.

strict makes you follow all the rules if you want your page to validate... i think that validation is important, cause if your page doesn't validate, it may still look fine, but then what happens when browsers are updated and follow standards more closely? your page can break. this is why i use strict doctypes. it's less lazy.

xhtml, in 99% of all cases is used incorrectly - or better yet, used unnecessarily... so i never use it. it's worthless for most webpages.

frames have been done with since 1999, so frameset is worthless (don't use frames).

note that i'm no expert - that's just my understanding of these things.
Copy linkTweet thisAlerts:
@dlr21authorJan 09.2008 — hi,

thanks for the replys chaps. Scragar, can you give me a simple concrete example of where declaring the wrong dtd will break a page? frames seem to work ok in strict despite not being supposed to so... (frames are just an example dtm)

picking up on what you said scragar, if the content-type is not xml (but,text/html), then does the browser not bother with any xml/xhtml declarations and tags etc and process the page as html?


mmm, the rabbit hole goes deeper.

dean.
Copy linkTweet thisAlerts:
@dtm32236Jan 09.2008 — if the content-type is not xml (but,text/html), then does the browser not bother with any xml/xhtml declarations and tags etc and process the page as html[/quote]

that sounds correct, but i'm not sure.

in any case, IE doesn't support xml/xhtml, and it's sadly still the most commonly used browser... so the way i see it, xml/xhtml is worthless (i'm sure i'll catch a lot of crap for that comment).

(frames are just an example dtm)[/quote]

hahahah. I won't jump down your throat for that - some people still use frames... that's their call. i just thought i'd point out that they're done with.
Copy linkTweet thisAlerts:
@Major_PayneJan 09.2008 — From the W3C:

When authoring document is HTML or XHTML, it is important to Add a Doctype declaration. The declaration must be exact (both in spelling and in case) to have the desired effect, which makes it sometimes difficult.[/QUOTE]

Use a correct doc type regardless: [B]Doc Types[/B]

Let's at least try to use the correct standards for your pages. One day it might be a real pleasure surfing the 'Net because everyone is on the "same page".

Ron
Copy linkTweet thisAlerts:
@dlr21authorJan 09.2008 — hi,

thanks for all your replies. further, when a browser that gets a page served as txt/html with a xhtml doctype, i understand that it processes the page in standards mode but as a html document. if the doctype is xhtml strict, does it 'fall back' to html 4.01 strict? in other words which 'standards'.

cheers again,

deano.
Copy linkTweet thisAlerts:
@scragarJan 09.2008 — if a page is servered as html, but contains an xhtml doctype it uses quirks mode.

if a page is servered as xhtml and contains a HTML doctype then terrible things will happen with regard to how the page is treated(go ahead and try it - use firefox: http://scragar.mybesthost.com/meap.php ).
Copy linkTweet thisAlerts:
@callumdJan 10.2008 — Here's a tutorial on DOCTYPEs that explains:

  • * Why DOCTYPEs came about

  • * What happens if you don't use a DOCTYPE

  • * The differences between the DOCTYPEs


  • Actually, I [i]wrote[/i] the tutorial, and I'd love to get some feedback from people on what they think about it.
    Copy linkTweet thisAlerts:
    @dlr21authorJan 10.2008 — if a page is servered as html, but contains an xhtml doctype it uses quirks mode.[/QUOTE] - is it? not according to http://msdn2.microsoft.com/en-us/library/bb250395.aspx#cssenhancements_topic2

    ive found very contradictory advice on using xhtml and serving it as text/html (which is the norm for ie) some say its in quirks mode, other say standard compliant mode (which standard if its not treates as xhtml but html, the doctype dtd, its 'own'?)

    is html 4.01 the simplest way to go?

    dean
    Copy linkTweet thisAlerts:
    @dtm32236Jan 10.2008 — is html 4.01 the simplest way to go?[/quote]

    yes, again... IE doesn't support xml/xhtml - and chances are, your site doesn't use anything that requires xhtml anyway.

    use HTML 4.01.
    Copy linkTweet thisAlerts:
    @scragarJan 10.2008 — xhtml needs to be served as application/xhtml+xml or application/xml otherwise it can NEVER be seen as xhtml, this is OK for IE, it doesn't understand xhtml to begin with, but the good browsers(anything using geko or khtml etc...) all treat the xhtml doctype as being invalid(which it is, since the page CANNOT be treated as xhtml since it was server wrong).

    and yes, it is far easier to use HTML, and xhtml only if you want it, although I love the way xhtml forces you to write it properly, with any luck that'll be the way the future goes.
    Copy linkTweet thisAlerts:
    @dtm32236Jan 10.2008 — Here's a tutorial on DOCTYPEs that explains:

  • * Why DOCTYPEs came about

  • * What happens if you don't use a DOCTYPE

  • * The differences between the DOCTYPEs


  • Actually, I wrote the tutorial, and I'd love to get some feedback from people on what they think about it.[/quote]


    that's a great tutorial - perfect for anyone that wants to understand Doctypes. I'll recommend it to anyone that ever asks about a doctype here.
    Copy linkTweet thisAlerts:
    @drhowarddrfineJan 10.2008 — 1) When xhtml is served as html, browsers treat the xhtml as broken html, or "tag soup", and make the best of it. It works fine but does not use quirks mode in any way.

    2) When properly served xhtml includes the proper xml declaration (not the doctype) on the first line, IE chokes and goes into quirks.

    3) IE supports XML but not XHTML.
    Copy linkTweet thisAlerts:
    @Jeff_MottJan 10.2008 — I love the way xhtml forces you to write it properly, with any luck that'll be the way the future goes.[/quote]XHTML doesn't add nearly as much as people tend to think. You're forced to quote attributes and write end-tags, but that's basically the end of it.

    [list]
  • [*]HTML is just as strict about nesting elements as is XHTML.

  • [*]You still need to escape special characters in HTML just as you do in XHTML.

  • [*]You still have the choice to use either the [i]id[/i] or [i]name[/i] attribute in XHTML as you do in HTML.

  • [*]And XHTML doesn't force or even suggest that styles and scripts be separate from the document any more so than HTML already does.

  • [/list]
    Copy linkTweet thisAlerts:
    @felgallJan 10.2008 — There is an appendix to the XHTML 1.0 standard that specifies how XHTML should be coded so as to be able to be treated as HTML with an occasional extra / at the end of a tag that browsers will ignore. Apart from that the only differences between HTML and XHTML are that HTML specifies some things to be optional that should be mandatory in a properly coded web page. These things are only optional in order that the standards can specify what browsers should do when those things are left out so as to be able to handle code written by people who don't really know what they are doing.

    Browsers will treat both HTML 4.01 strict and XHTML 1.0 strict as being the same doctype if the page is served as HTML (and similarly for the transitional ones). The only browser where the XML tag coming before the doctype makes a difference is IE6, Microsoft fixed that bug for IE7.

    Not specifying a doctype or specifying an incomplete doctype will put browsers into quirks mode where each browser does its own thing in working out how to display a page.

    Internet Explorer populates different fields with browser related information in JScript depending on whether or not you use a strict doctype (properties within document.documentElement instead of document.body).

    While the browser doesn't actually use the doctype for its real purpose for pages served as HTML the doctype you use does still make a number of differences regarding how the browser processes the page. For anything in the code that doesn't validate according to the standards for the specified doctype the individual browsers are free to choose how to handle the code and so using code that is inappropriate for your chosen doctype increases the chance that your page will not display the same in all browsers.
    Copy linkTweet thisAlerts:
    @Major_PayneJan 10.2008 — These aren't totally definitive, but should go a long way in explaining the subject:

    [B]Quirks mode[/B]

    [B]Web standards and maturing technologies in popular web browsers[/B]

    [B]Quirks mode and strict mode[/B]

    [B]Rendering Mode and Doctype Switching[/B]

    [B]Serving XHTML 1.0[/B]

    Ron
    Copy linkTweet thisAlerts:
    @toicontienJan 10.2008 — I wrote about this on a similar topic a while ago. Might be a good read:

    About DOCTYPES
    Copy linkTweet thisAlerts:
    @dlr21authorJan 11.2008 — hi all,


    Browsers will treat both HTML 4.01 strict and XHTML 1.0 strict as being the same doctype if the page is served as HTML (and similarly for the transitional ones). The only browser where the XML tag coming before the doctype makes a difference is IE6, Microsoft fixed that bug for IE7.

    ...

    While the browser doesn't actually use the doctype for its real purpose for pages served as HTML the doctype you use does still make a number of differences regarding how the browser processes the page. For anything in the code that doesn't validate according to the standards for the specified doctype the individual browsers are free to choose how to handle the code and so using code that is inappropriate for your chosen doctype increases the chance that your page will not display the same in all browsers.[/QUOTE]



    this answers my question, so thanks a lot fellgall. I originally couldn't understand the use of doctype in xhtml pages served as html or rather the statement 'treated as html'. but now...although the page is treated as html (so no use of xml or the likes of mathml), it does pay attention to the exact doctype specified and tries to comply to the standard set there.

    cheers again.
    Copy linkTweet thisAlerts:
    @callumdJan 13.2008 — that's a great tutorial - perfect for anyone that wants to understand Doctypes. I'll recommend it to anyone that ever asks about a doctype here.[/QUOTE]
    Thanks [b]dtm32236[/b].
    ×

    Success!

    Help @dlr21 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...