Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use HTML5 features without declaring the HTML5 DOCTYPE?

Tags:

html

doctype

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?

like image 887
Mark Bubel Avatar asked Aug 30 '11 19:08

Mark Bubel


People also ask

Does HTML5 work without DOCTYPE?

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.

Is doctype declaration necessary in HTML5?

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.

What happens if you don't declare DOCTYPE HTML?

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.

Is it compulsory to write DOCTYPE HTML?

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.


2 Answers

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.

like image 194
Jani Hartikainen Avatar answered Oct 06 '22 02:10

Jani Hartikainen


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.

like image 38
Madara's Ghost Avatar answered Oct 06 '22 02:10

Madara's Ghost