Syntax of a doctype tag
The first thing to notice about a doctype tag it is always the first tag in a document. It goes on the first line before the <html> tag. This is because it has to be the first element that the browser processes. It would not be possible to suddenly change the doctype once the browser had begun to work out how to render the page.
Below is the doctype declaration for html 4.01 transitional.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The structure of the tag is also different to all other html tags. The very first thing to notice is that the tag begins with a exclamation mark (!). This is technically as it is a xml processor statement not a html tag at all.
Next comes the word DOCTYPE this must be in upper case. next comes the section declaring which version of html you are going to use using. Typically this might look like
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
taken from the beginning this declared the document to be html and then the quoted section tells the browser which version of html the document conforms to, in this case html 4.01 transitional. This is done by specifying which DTD the browser is to use when rendering the document. In other words the exact rules for each tag within the document.
The next section of the tag is unique. There now follows a line break and a tab. This is not seen in any other html tag. On this new line there should be a url for the dtd. This further ensures that the browser renders the document correctly. Some browsers contain a "internal" version of the various dtds but these may differ from the W3Cs definitions. If the browser is standards compliant this final section should ensure that the correct W3C dtd is used.
This two part mechanism means that if new types of xml based document are produced it should then be possible to tell a browser how to deal with them through a doctype declaration
Not all doctype declarations have the url element. This is because they refer to a dtd that is standard across all browsers. For instance the doctype for html 2.0 is
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
also note the differences in the capitalization and that the document was not produced by the W3C.
