Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the DOCTYPE declaration have to be the first tag in an HTML document? [duplicate]

Tags:

html

doctype

Our security manager dynamically inserts a bit of javascript at the top of every html page when a page is requested by the client. It is inserted above the DOCTYPE statement. I think this might be the cause of the layout problems I am having.

Ideas anyone?

like image 408
paul Avatar asked Sep 16 '08 06:09

paul


People also ask

Should a doctype declaration be the first thing in an HTML document?

The doctype comes first The very first thing you should make sure to have in any HTML document you create is a DTD declaration.

Does DOCTYPE have to be on the first line?

A doctype declaration tells the browser that the page to be rendered is written in HTML. To declare an HTML5 doctype, `<! DOCTYPE html>` is required in the first line of your HTML document. Doctype declaration for HTML5 is not case sensitive and does not require a closing tag.

Which DOCTYPE is correct declaration for HTML?

Definition and Usage 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 when <! DOCTYPE HTML is not written as first line of HTML5 document?

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.


1 Answers

Yes, the DOCTYPE must come first.

The definition is here: http://www.w3.org/TR/REC-html40/struct/global.html. Note that it says a document consists of three parts, and the DTD must be first.

like image 94
Brad Wilson Avatar answered Oct 13 '22 01:10

Brad Wilson