2

What sorts of problems would we face if we don't include doctype and would clarifying <!DOCTYPE html> be okay for all new and old browsers?

What are the problems of not including <!DOCTYPE html>?

I already have read Stack Overflow question What's up, DOCTYPE?, but it didn't find out the problems. I would like to know some problem, that sometimes an answer giver says you should define <!DOCTYPE html> for another type of questions which is facing the problem after then that is solved, like that I would like to know sorts of problems.

Community
  • 1
  • 1
luxi
  • 317
  • 1
  • 4
  • 17
  • 1
    it is immposible to exactly notify the exact problems with out your markup. – Jawad Apr 28 '13 at 03:17
  • Would I face any kind of problem? – luxi Apr 28 '13 at 03:17
  • offcourse you would face problems. even if u had a very simple document such as @j08691's, the first would be that your page will load in quirk mode which will lead to others problems. Secondly your page will not validate. Even ignoring all other issues, these two reasons alone are sufficient to start using doctype. Part from the fact that you may not also able to use new HTML5 features. – Jawad Apr 28 '13 at 03:22
  • And lastly but not the least, the developer community will frown upon your work for not using a doctype – Jawad Apr 28 '13 at 03:23

1 Answers1

7

The best answer comes from MDN:

In the old days of the web, pages were typically written in two versions: One for Netscape Navigator, and one for Microsoft Internet Explorer. When the web standards were made at W3C, browsers could not just start using them, as doing so would break most existing sites on the web. Browsers therefore introduced two modes to treat new standards compliant sites differently from old legacy sites.

There are now three modes used by the layout engines in web browsers: quirks mode, almost standards mode, and full standards mode. In quirks mode, layout emulates nonstandard behavior in Navigator 4 and Internet Explorer 5 for Windows that is required not to break existing content on the Web. In full standards mode, the behavior is (hopefully) the behavior described by the HTML and CSS specifications. In almost standards mode, there are only a very small number of quirks implemented.

How do browsers determine which mode to use?

For HTML documents, browsers use a DOCTYPE in the beginning of the document to decide whether to handle it in quirks mode or standards mode. To ensure that your page uses full standards mode, make sure that your page has a DOCTYPE like in this example:

<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8>
<title>Hello World!</title>   
</head>
<body>
</body> 
</html>

The DOCTYPE shown in the example, , is the simplest possible, and the one recommended by HTML5. Earlier versions of the HTML standard recommended other variants, but all existing browsers today will use full standards mode for this DOCTYPE, even the dated Internet Explorer 6. There are no valid reasons to use a more complicated DOCTYPE. If you do use another DOCTYPE, you may risk choosing one, which triggers almost standards mode or quirks mode.

Make sure you put the DOCTYPE right at the beginning of your HTML document. Anything before the DOCTYPE, like a comment or an XML declaration will trigger quirks mode in Internet Explorer 9 and older.

In HTML5, the only purpose of the DOCTYPE is to activate full standards mode. Older versions of the HTML standard gave additional meaning to the DOCTYPE, but no browser has ever used the DOCTYPE for anything other than switching between quirks mode and standards mode.

To answer your second question, it's recommended that you use the HTML5 doctype: <!DOCTYPE html> which triggers standard mode in every browser (including IE6).

j08691
  • 204,283
  • 31
  • 260
  • 272
  • I have read that but actually I want to know the problems arising of not defining doctype. – luxi Apr 28 '13 at 03:09
  • The problems are non standard behavior which is essentially quirks mode. See also https://developer.mozilla.org/en-US/docs/Mozilla_Quirks_Mode_Behavior – j08691 Apr 28 '13 at 03:11
  • 2
    the problems that may arise due to not defining a doctype depends on your markup. In a simple doc, there may be no problems at all. In others you may have broken layout, float issues, alignment problems, content no appearing at all, defined fonts not showing up, images out of place, no reponsive media queries capabilities and so on and so forth. – Jawad Apr 28 '13 at 03:15
  • @Jawad Exactly that I wanted to know. – luxi Apr 28 '13 at 03:16
  • Why wouldn't you define a doctype? – j08691 Apr 28 '13 at 03:17
  • Just wanted to know importance of this. – luxi Apr 28 '13 at 03:25