Home  >  Q&A  >  body text

What is the purpose of DOCTYPE?

I understand that the different document types are essentially about html compliance, but what difference does it make to the document type you specify? Will browsers handle the same code differently depending on document type? Thanks

Update - Most answers mention that weird mode can be turned off if the document type is not specified. But what is the difference between xhtml and html 4.01?

P粉779565855P粉779565855264 days ago451

reply all(2)I'll reply

  • P粉163465905

    P粉1634659052024-01-29 15:36:22

    From Wikipedia:

    I decided to quote this passage because it answers your question better than mine :). Importantly, missing DOCTYPE will trigger "weird mode" in some browsers.

    reply
    0
  • P粉270891688

    P粉2708916882024-01-29 00:56:30

    The most important thing is whether there is a document type. If you don't do this, the browser will work in "weird" mode instead of standard mode, and many things will be slightly different. If you have one (any of them), it usually activates more standards-compliant behavior in the browser.

    See this article to learn more about the role of doctype in various browsers and the modes - quirks, standards, quasi-standards, etc. - that different browsers have. Quote the relevant part:

    ...but see the article for a full discussion.

    reply
    0
  • Cancelreply