0

What's the difference between these two? I read that the first simply refers to a HTML5 page. What about the second one? Is there any real difference between the two? Thanks.

  1. <!DOCTYPE html>

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

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
user697911
  • 10,043
  • 25
  • 95
  • 169

1 Answers1

1

A document type declaration (DOCTYPE) tells the browser – or any other tool processing your document – which version of HTML or XHTML your document is using.

There are many DOCTYPEs, because there are many versions of HTML/XHTML (e.g. HTML 4.01 (Transitional), HTML 4.01 (Strict), XHTML 1.0 (Strict), etc. However, as of HTML5, the only DOCTYPE you need to know and use is <!DOCTYPE html>.

The bottom line is you want to trigger standards mode (as opposed to quirks mode) in your browser when processing the document. Among your two options, just use #1, it's shorter and easier to remember.

Further reading:

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
  • But the declaration 2 is used in a JSF tutorial example. How is it different from only? Is the 2nd declaration also a HTML5 declaration? – user697911 Sep 25 '15 at 00:24
  • Older doctypes can still be used. But if you try to use new HTML5 elements in a document with an older DOCTYPE, you will get validation errors. – Michael Benjamin Sep 25 '15 at 00:26
  • So you mean the 2nd one is an older doctype declaration, i.e. HTML4? It's used in a JSF example. Is a JSF file also a HTML file? – user697911 Sep 25 '15 at 00:29
  • The first DOCTYPE in your list is the most modern, because HTML5 is the most modern. Selecting a DOCTYPE before HTML5 was an ambiguous and somewhat confusing process (there were many options). No longer. It's very simple, easy and straightforward now. Use #1 and you're set. – Michael Benjamin Sep 25 '15 at 00:35
  • Based on this: http://www.w3.org/QA/2002/04/valid-dtd-list.html, to specify a doc is a JSF file, it's better to use the 1st declaration? Because it's explicitly says it is an XHTML file (JSF)? – user697911 Sep 25 '15 at 00:41
  • If you have an XHTML file, and it is being served as XHTML (which I would think is very rare), then you need to use an XHTML doctype. When XHTML was in its prime years back, it was still being served mostly as `text/html`, so it was an HTML document nonetheless. – Michael Benjamin Sep 25 '15 at 00:47
  • I was focusing my answer and comments on your question. I apologize I'm not familiar with JSF. – Michael Benjamin Sep 25 '15 at 00:59