Mark Bubel
Mark Bubel

Reputation: 375

Can you use HTML5 features without declaring the HTML5 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?

Upvotes: 9

Views: 7205

Answers (3)

Jani Hartikainen
Jani Hartikainen

Reputation: 43243

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.

Upvotes: 10

Winfield Trail
Winfield Trail

Reputation: 5695

You can, but the behavior will be undefined. This means that your results may be [even more] inconsistent across browsers, and that it may fail in some circumstances for unknown reasons.

It definitely won't validate, and it is certainly not something you should do.

Upvotes: 0

Madara's Ghost
Madara's Ghost

Reputation: 174957

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.

Upvotes: 1

Related Questions