So, for example, if my HTML document does not declare the HTML5 doctype, but I use something in the HTML5 spec, will that still work? Does that cause problems for some browsers? Will the document still validate?
It is not valid to omit the DOCTYPE. There is no “Standard” format. The browser will just try to parse HTML as best it can. But not all elements will be displayed correctly.
All HTML documents must start with a <!DOCTYPE> declaration. The declaration is not an HTML tag. It is an "information" to the browser about what document type to expect.
The absence of the DOCTYPE or its incorrect usage will force the browser to switch to quirks mode. It means that the browser will do its best to layout the page that is considered to be old or created against web standards.
Even though a doctype may look a bit strange, it is required by the HTML and XHTML specifications. If you don't include one you will get a validation error when you check the syntax of your document with the W3C Markup validator or other tools that check HTML documents for errors.
It depends on the target browsers. Webkit-browsers, Firefox and Opera will handle HTML5 elements quite normally even if your doctype is not HTML5.
IE9 on the other hand (I bet you saw this coming), may behave entirely differently on another type of doctype. If IE9 is not in IE9 Standards mode (it could be in quirks, IE8 compat, whatever), it will not support the HTML5 features it does in IE9 standards.
So essentially your main concern is that you need to make sure all browsers go into strict standards mode. The easiest way to achieve this is to use the HTML5 doctype, since it will trigger standards mode in all browsers - including older browsers that don't actually support HTML5.
Yes, you can, however, it will not validate and possibly look weird in some or all browsers. You shouldn't do it. If you are using HTML5, declare a proper doctype: <!doctype html>
.
In the HTML5 specs, it says that the doctype is not mandatory, however, no browser wide browser implementation of that rule yet exists. In theory, you should be able to do it without any problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With