A doctype (Document Type Declaration) should be included at the top of xhtml code above the <html> tag. It is used by validators such as the W3C XHTML/HTML validator to determine the rules to use when validating source code. It informs the validator which version of XHTML/HTML is being used, and is a key component of modern compliant web pages.
Modern browsers use the doctype to decide whether to display the web page in Quirks mode or Standards mode and inform the validator which version of XHTML/HTML is being used. Doctypes are a key component of compliant web pages. Markup and CSS will not validate without them.
Tools such as a markup validator use the doctype to check the syntax of the XHTML/HTML. Errors can then be found that may affect the way the page is rendered by the browser. These tools do not work if they do not know what kind of web page it is.
The doctype declaration will remove unnecessary guessing by the browser. It will trigger the standard parsing mode and make the display of the web page faster, consistent and free of any nasty surprises.
Using an incomplete or outdated doctype, or no doctype at all, puts browsers into Quirks mode.
Quirks mode refers to a technique used by some web browsers to maintain backward compatibility with web pages designed for older browsers, where the browser assumes old-fashioned invalid markup as per the industry norms of the late 1990s.
In Quirks mode, the browser will attempt to parse the page in backward-compatible fashion, rendering the CSS as it might have looked in IE4, and reverting to a proprietary, browser-specific DOM.
This is not what we want, but it is often what we get where a correct doctype is not used.
So be sure to use a correct doctype so that the browser can render your page in the way that you intended.
GO Soft uses the XHTML 1.0 Strict doctype, and this is what it looks like:
Below is a list of doctypes which, when used, will put modern browsers into 'Standards' mode.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
"http://www.w3.org/TR/html4/frameset.dtd">
HTML 5 recommends the use of the very simple doctype <!DOCTYPE HTML> and suggests that doctypes are headers that, although required, are mostly useless. A doctype should ensure that browsers render web pages in the correct, standards compliant mode and the above doctype will do that, including in IE8. For future proofing your web pages, this may be the doctype to go with.
<!DOCTYPE HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
The XHTML 1.1 document type is a fully functional document type with rich semantics. It does not contain any of the deprecated functionality of XHTML 1.0 or HTML 4. Despite these exceptions, or perhaps because of them, the XHTML 1.1 doctype is a solid basis for future doctypes that are targeted at varied user agent environments.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Visit the W3C Validator and validate your source code.
The doctype will drive how the validator checks your source code. Any code that fails to meet the required standard will generate an error message which will help you to make corrections until your code validates.