The history of the doctype declaration is a really long and varied one.
I'll give you a link to the details surrounding it a little bit later on.
But for the most part, the doctype is just one of those things
that not everybody understands exactly what it does.
They just know that they need one.
So, what the doctype is supposed to do is tell the browser or
user agent which version of HTML that you'll be using so
it knows which version of the syntax to use in parsing.
But in reality, all it's really doing is triggering something called quirks mode,
which ensures that your page is going to be rendered properly.
I know this probably sounds confusing, so I just want you to remember this.
You need to have a doctype declaration and
you want the doctype to reflect the version of HTML that you'll be writing.
Now, we're looking at a pretty old document right now.
This was put together in 2002 by the W3C.
I don't believe any of this quality assurance section is
being updated currently, but what this does for
us is it gives us a little bit more of information about the doctype declaration.
If you really want to read about it, this link right here takes you
to a page that discusses a little bit more about what the doctype declaration does,
why we need one, the history of it, that sort of thing.
Now, if I scroll down a little bit,
I can see a list of all of the different HTML and XHTML doctype declarations.
We really don't have to use these anymore, but
the reason I'm showing you these is because a lot of you guys are probably
going to be editing documents that were created earlier or some legacy files.
Or you're going to open up an HTML file from another site to kind of
learn from and you're going to see this stuff up top and
you're going to go, oh my gosh, what is all this stuff?
Well, there were different versions of HTML, XHTML.
We've kind of gone over a little bit of that history and
you're going to see that HTML, for
example, had three different flavors, Strict, Transitional and Frameset.
XHTML had the same three, Strict, Transitional, Frameset.
So depending on which version you're using, you would use a different
doctype declaration and you can see these had a lot of information in it.
It was HTML.
It pointed back to the document type declaration, that sort of thing.
And if I scroll down, I can see that there's actually a lot of these.
The only one that we need to concern ourselves with is this one right here,
down toward the bottom, where it says HTML 5 NOT a standard yet.
Remember, this is 2002.
They didn't know what was coming.
It is the standard now and this is all we need.
It's very simple.
It's very basic.
It basically just says DOCTYPE HTML.
It doesn't worry about versioning numbers.
It doesn't worry about a document type declaration file to point back to.
It just tells the user agent, hey, an HTML document is on the way.
All right, so what I want to do now is I'm going to go to our code editor.
And for the rest of this chapter,
we're going to start building a simple HTML page.
The very first thing that you're going to do whenever you create an HTML page
is start with the document type declaration.
So, go into the 02_02 directory and open up doctype.htm.
Here comes the really hard part.
What you're going to do is you're going to open up a right angle bracket, then you're
going to do an exclamation point, and then you're going to type in the word doctype.
Now, sometimes you're going to see this capitalized in all caps.
Sometimes it's going to be lowercase.
It does not matter.
And then after that, you're going to see html and then the right angle bracket.
That's it.
That's your document type declaration.
A lot of people would copy and
paste them in the past, but that's actually pretty easy to remember.
But you want that to appear at the very top of each of your HTML documents.
And if you're ever creating templates for yourselves or
boiler plates, make sure that your boiler plate is going to have it.
So that ought to be the very first thing that you do when creating a new
HTML document.
Now, if you want to use one of the older document types to indicate
a specific version of HTML or XHTML, you can do that.
You just go to that site that I showed you and copy and paste those.
I do want to point out that there's no compelling reason to do it anymore.
Pretty much every document that you create from this point forward can
just use the standard very easy HTML5 doctype, so that's what I recommend.