HTML5 is not based on SGML, and therefore does not require a reference to a DTD
Asked Answered
K

3

5

From: http://www.w3schools.com/tags/tag_doctype.asp

The < !DOCTYPE > declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.

In HTML 4.01, the < !DOCTYPE > declaration refers to a DTD, because HTML 4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly.

HTML5 is not based on SGML, and therefore does not require a reference to a DTD.

Tip: Always add the < !DOCTYPE > declaration to your HTML documents, so that the browser knows what type of document to expect.

Does the bold statement mean that when we are using HTML 5 we don't need to specify < !DOCTYPE html >?
What does that statement exactly mean?

I am currently using < !DOCTYPE html > in my html file with the browser Firefox 4. I removed that declaration but did not see any difference in the rendered output. Does it mean that the problem may occur in old browsers and not in new ones?

Karinakarine answered 24/4, 2013 at 6:26 Comment(4)
Do not use w3schools as source of information (just for fun, if you like). See w3fools.com for some explanations. The quoted text is confused and confusing.Fiacre
@JukkaK.Korpela Okay, thanks, will take care next time. What site do you suggest then in replacement?Karinakarine
I recommend developer.mozilla.org for example, and the specifications at w3.org when you need to get very technical and theoretical.Fiacre
See also #255970Hypothecate
H
7

The terminology is confusing, but a DTD (document type definition) is only one part of a document type declaration (usually shortened to "doctype"). You should always include a doctype declaration (<!DOCTYPE html> if you use HTML5), but a document type definition identifier is no longer necessary.

To provide a concrete example, this is what a HTML4.01 document type declaration ("doctype") might have looked like:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

The document type definition ("DTD") identifier in the above declaration is this part:

"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"

That's the part you can leave off for HTML5. "PUBLIC" specifies the DTD's availability, so that should also not be included if there is no DTD.

Holston answered 24/4, 2013 at 6:43 Comment(1)
Long story short, just type <!doctype html> (case-insensitive) at the top of your HTML documents.Holston
F
4

Does the bold statement mean that when we are using HTML 5 we don't need to specify ?

It means that you can't specify.

The HTML 5 Doctype has no public or system identifier in it.

I am currently using <!DOCTYPE html> in my html file

That is required. Keep doing that.

with the browser Firefox 4.

The current stable version of Firefox is version 20. You should probably upgrade.

I removed that declaration but did not see any difference in the rendered output. Does it mean that the problem may occur in old browsers and not in new ones?

No, it just means that you don't have any code that is impacted by being in Quirks mode (or that you do but didn't spot the changes).

Flagstone answered 24/4, 2013 at 6:30 Comment(3)
It means that you can't specify. Do you mean that when I am using HTML 5 I can't specify < !DOCTYPE >? If yes, then how do I know which HTML standard am I using? Besides that link says that < !DOCTYPE HTML > stands for HTML 5. Please clarify.Karinakarine
@AnishaKaul: See my answer, "DTD" and "doctype" are not synonyms. I think that's where your confusion is coming from.Holston
@MattKantor That was my confusion perhaps.Karinakarine
I
1

Lets take a look at the W3C HTML5 definition, they have a conveniënt page about the differences HTML5 brings: http://www.w3.org/TR/html5-diff/#doctype

2.2 The Doctype

The HTML syntax of HTML5 requires a doctype to be specified to ensure that the browser renders the page in standards mode. The doctype has no other purpose. [DOCTYPE]

The doctype declaration for the HTML syntax is and is case-insensitive. Doctypes from earlier versions of HTML were longer because the HTML language was SGML-based and therefore required a reference to a DTD. With HTML5 this is no longer the case and the doctype is only needed to enable standards mode for documents written using the HTML syntax. Browsers already do this for .

To support legacy markup generators that cannot generate the preferred short doctype, the doctype is allowed in the HTML syntax.

The strict doctypes for HTML 4.0, HTML 4.01, XHTML 1.0 as well as XHTML 1.1 are also allowed (but are discouraged) in the HTML syntax.

In the XML syntax, any doctype declaration may be used, or it may be omitted altogether. Documents with an XML media type are always handled in standards mode.

On that page, chapter 1 (Introduction) says more about HTML versus XML syntax:

The HTML5 draft (..) defines a single language called HTML which can be written in HTML syntax and in XML syntax.

So, if your HTML5 is strict XML syntax, i can conclude from the last paragraph that yes in this case you should not prefix a doctype line.

See chapter 2 for the difference in syntax:

HTML5 HTML syntax:

<!doctype html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Example document</title>
  </head>
  <body>
    <p>Example paragraph</p>
  </body>
</html>

HTML5 XML syntax:

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Example document</title>
  </head>
  <body>
    <p>Example paragraph</p>
  </body>
</html>

There is some subtle differences in syntax.

Isallobar answered 24/4, 2013 at 6:38 Comment(2)
It's possible to create documents that can be served as XML or HTML without changes.Holston
@MattKantor Interesting, thanks! I removed my "You may not mix the two." line.Isallobar

© 2022 - 2024 — McMap. All rights reserved.