"<!DOCTYPE html>" What does it mean?

98,699

Solution 1

<!DOCTYPE html> is the explicit Document Type Declaration.

From the linked page:

The DOCTYPE Declaration (DTD or Document Type Declaration) does a couple of things:

  1. When performing HTML validation testing on a web page it tells the HTML (HyperText Markup Language) validator which version of (X)HTML standard the web page coding is supposed to comply with. When you validate your web page the HTML validator checks the coding against the applicable standard then reports which portions of the coding do not pass HTML validation (are not compliant).
  2. It tells the browser how to render the page in standards compliant mode.

#2 is a very important reason for using it.

<!DOCTYPE html>, specifically, is the correct declaration for HTML5, and should be used pretty much from here to the near future. You can still use legacy strings or obsolete permitted strings, but the previously written format is all that is required in HTML5. On a further note, this DTD will cause all modern browsers dead link to switch to their standards (compliance) mode, even if they don't support HTML5.

Here's some more info:

Activating Browser Modes with Doctype & Choosing a Doctype (same page)
World Wide Web Consortium (they make web standards)

Solution 2

<!DOCTYPE html> is not a "Document Type Declaration".

A "Document Type Declaration" is an SGML concept for signalling the mark-up syntax and vocabulary for the mark-up that follows. <!DOCTYPE html> does not conform to the requirements of that. This is unlike <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> which is a SGML conforming Document Type Declaration.

<!DOCTYPE html> does not indicate an HTML5 document.

Although HTML5 conforming documents in the text/html serialization are required to have <!DOCTYPE html> at their start, it does not follow that the converse is true. I.e. a document can have <!DOCTYPE html> at its start and not be an HTML5 document. For example, it is intended that all future versions of HTML will use the same character sequence at their start. So it might indicate an HTML5 document, or an HTML6, HTML7 etc. document, an HTML5+RDFa-lite document, or a document from an entirely competing standard.

The HTML5 spec describes <!DOCTYPE html> as "a required preamble", and that's much closer to the mark.

It's just the shortest character sequence that will request to legacy as well as future browsers that the browser should handle the HTML of the document using its most modern HTML processing mode. It was chosen as the conforming preamble for HTML5 for solely that reason.

If it can be said to have any meaning at all, it is that it indicates that the document was created or last refactored around about 2007 or later. Again, the converse does not necessarily apply. A document not containing <!DOCTYPE html> does not imply that the document was created before any particular date.

Solution 3

“<!DOCTYPE html>” What does it mean?

It means that your webpage will be rendered as per html5 standards, obviously you if you have something that browser doesn't support then you need to use a polyfill for that.

Share:
98,699
zono
Author by

zono

Updated on November 03, 2020

Comments

  • zono
    zono over 3 years

    I use a fantastic javascript organization tree generator named "ECOTree" but the drawing does not work when I put <!DOCTYPE html>. Labels in the boxes are not put in the boxes correctly.

    You can see the error at sample1.htm on the site below. Could anybody suggest me how to fix. http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=16192

    (In order to follow my project rule, I have to define <!DOCTYPE html>)

    • Blender
      Blender about 12 years
      <!DOCTYPE html> is the doctype for the document. It basically tells the web browser how to render the page (there are different doctypes). If the page renders improperly with a correct doctype, that means that the page wasn't correctly coded.
    • animuson
      animuson about 12 years
      possible duplicate of What's up, Doctype?
    • zono
      zono about 12 years
      Thaks a lot! As you said, this question is duplicated one. I will read it.(It may be tough one to find unsupported codes from "ECOTree" but I will try it.)
    • zono
      zono about 12 years
      Fixed it thanks to the message-board in ECOTree's site.Additionally, I learned what does "DOCTYPE" mean thank to you.
    • Jawad
      Jawad about 12 years
    • toesslab
      toesslab almost 10 years
      -1 Searched SO with '<!DOCTYPE html> What does it mean?' found over 600 results!
  • rockerest
    rockerest about 12 years
    @thirtydot "we should be thinking for ourselves when deciding what specific page is a good reference, not relying on a blanket statement made by a 3rd party." If a link provides information that is not incorrect (as the link did), and is easy to absorb for someone who obviously has no idea about the subject, then it is a good link. The link you provided is like getting hit in the face with with a book. Quality information, I'm sure, but on the level of a theoretical white paper as to layman usefulness.
  • BoltClock
    BoltClock about 12 years
    "html is the declaration for HTML5" Uh, no, not really. In a valid DOCTYPE declaration, it just means the root element of the document is <html>. The sequence <!DOCTYPE html> is taken as a whole by the HTML5 spec.
  • thirtydot
    thirtydot about 12 years
    I removed the w3schools link mainly because it doesn't even mention the HTML5 doctype. In 2012, that's just no good. Linking to w3schools is almost never a good idea. Their information is often flawed in some way, and even if it's not, you're less likely to get upvotes and more likely to get downvotes (personal experience). To mitigate your concerns that the link I provided is too complicated, you could update the link to hsivonen.iki.fi/doctype/#choosing, which gets straight to the important part. Thanks for not rolling back your answer.
  • rockerest
    rockerest about 12 years
    @BoltClock I made that paragraph more clear as to what I meant. Thanks for pointing that out.
  • rockerest
    rockerest over 10 years
    For posterity: the World Wide Web Consortium's list of document type declarations. Explicitly noting that <!DOCTYPE html> is a Document Type Declaration, though not officially standardized yet. In addition, the link in the answer above explicitly states that other DTDs are obsolete when creating HTML documents
  • Greg Wozniak
    Greg Wozniak about 3 years
    Quote from that website: "The simplest and most reliable doctype declaration to use is the one defined in HTML5: <!DOCTYPE html>"