Skip to content Skip to sidebar Skip to footer

Is It Neccessary To Add HTML Doctype At The Starting Of The Web Page

Is it neccessary to write doctype at the starting of the HTML page? E.g. If I use this doctype and in the HTML file :

Solution 1:

Technically, no, you dont need a doctype to get something to display on the page. In practice however, you definitely should.

A doctype is essentially a protocol that dictates how each element on the page should be displayed, which tags are valid etc. etc.

The existence of doctypes, means that web browsers can be developed against this doctype, to ensure they render all elements correctly.

When the doctype is not present, the browser resorts to interpreting the HTML itself (often called quirks mode). While most modern browsers make a fairly good attempt at this (provided the html is relatively well formed), there can still be inconsistencies the way browsers choose to display elements.

So in short, the use of a doctype means that you can rely (for the most part) on your page rendering the same in every browser, making development significantly easier.


Solution 2:

The reason for your layout changing with and without a doctype is because without a doctype a browser goes into quirks mode which doesn't render your layout as consistently as it would with a doctype across the multitude of browsers, most notably Internet Explorer.

A full rundown of the history and rendering differences can be found at QuirksMode


Solution 3:

The DOCTYPE tag tells the browser in wich version of the marckup (in this case XHTML 1.0 Transitional) is the document written.

So the proper way is to use it and then write the documment following the dtd indicated by DOCTYPE.

I'd suggest to check the valid DOCTYPEs ( http://www.w3.org/QA/2002/04/valid-dtd-list.html ) and validate your document afterwards ( http://validator.w3.org/ ).

To place the tables on the document you can use CSS ( http://www.w3.org/Style/CSS/ ) and you can also validate your CSS ( http://jigsaw.w3.org/css-validator/ ).

Hope it helps :)


Solution 4:

Is it neccessary to write doctype at the starting of the HTML page?

Yes, it is necessary. See DOCTYPE by W3Schools

The table or the form is not coming at the center (horizontal and vertical) of the page.

Use CSS to specify locations of elements in the page.


Post a Comment for "Is It Neccessary To Add HTML Doctype At The Starting Of The Web Page"