DOCTYPE Declaration

From Htmlpedia
Jump to: navigation, search

DOCTYPE Declaration


A DOCTYPE declaration informs the user agent what dialect of HTML your document is written in. When you are writing standards-compliant HTML, the DOCTYPE declaration must be the first element in you document. If it is missing, the user agent will render the page in quirks mode, which can affect the final appearance of the page.


Good<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

This is the DOCTYPE for a document written in the XHTML Transitional dialect.


Be careful when using different DOCTYPEs with one style sheet! Suppose you have two HTML documents which share a common CSS file. One of the HTML documents has an XHTML 1.0 Transitional DOCTYPE, and the second has an XHTML 1.1 Strict DOCTYPE. Even if the two HTML files are identical except for the DOCTYPE they will render differently, because user agents interpret CSS instructions such as "padding-left: 10px" differently depending on the DOCTYPE.