View Full Version : Doctypes

06-10-2012, 02:36 AM
Hi guys, can someone really quickly tell me what a doctype is and the coding behind it. Basically if i construct website from codes i found on the internet etc will the codes be in different html 'formats'? and is there some sort of universal doctype i can use or do i have to define every type of html coding i used within that doctype?

06-10-2012, 02:49 AM
Hah, funny that you ask this question just when I recommended you to use one in your other thread.

A document type declaration (abbreviated “doctype”) tells the browser (or any program that reads the file) what it actually is that is written in the document. HTML has a predefined set of elements. The doctype declaration has a URI in it (e. g. http://www.w3.org/TR/html4/strict.dtd for HTML 4) where the elements are defined which is telling the browser what is valid and invalid HTML code.

You put the doctype in the beginning of your document and it has to be present in every new HTML file (there are exceptions which aren’t of concern right now, though).

06-11-2012, 12:07 AM
Doctypes are an SGML command that defines the markup language used by a particular document. SGML is the meta language used to define markup languages that provides doctypes as the main way to attach the markup definition to the front of a file so that any program should then be able to use that definition to decode the meaning of the document content.

Unfortunately browsers do not actually use the doctype for its intended purpose and instead have their own built in definition of HTML that they use - web pages therefore end up being processed by the browser against the same set of HTML rules regardless of which version of HTML the doctype specifies. If they used doctypes properly then HTML would be far more flexible.

Instead browsers simply use doctypes to switch between three different "modes" that they use to process the web page content. No doctype at all puts the page into quirks mode where the browser does completely its own thing as to how the page is rendered the same way that browsers used to in the days before IE6. A strict doctype applies as close to the actual HTML 4/CSS2.1/ECMAScript3.1 standards as the browser supports along with whatever parts of the following version of each that they have implemented (only ECMAScript 5 and some parts of CSS3 have been released as a stanard so the rest of CSS3 and HTML5 are still subject to change - just as CSS2 was still subject to change when IE5 was released which led to the need for quirks mode in the first place). A transitional doctype (which indicates that the page actually contains two different versions of HTML - usually 3.2 and 4) is half way in between and implements some things according to the standards and some things the way they were in quirks mode.