Nothing is for sale here. Freewill tips keep the site running. Want to help? → Tip via Paypal
HTML DOCTYPE
The doctype declaration should be the first thing in an HTML document, even before the opening <html> tag. Some say it's not case sensitive, and while that may be true, the W3C always show it capitalized in code examples, so that's what I recommend. The W3C, for those who don't know, write the coding standards. I'll use lower case here, accept in code examples and headings. Mainly because it looks stupid having doctype capitalized all over the page.The doctype declaration simply informs web browsers which mark-up language and which version of the markup language the page is written in so the browser can parse the code correctly.
Older doctype declarations refer to a Document Type Definition, or DTD for short. The DTD specifies the rules for the markup language so browsers can render the content according to established standards. That, thankfully, has been eliminated in HTML5.
HTML5 DOCTYPE
Here's the HTML5 doctype:That's all there is to it. You'll see in the older doctype below why I said the DTDs were "thankfully" done away with in HTML5. The older doctype below can still be used, but you're strongly encouraged to use the HTML5 doctype unless you have a very good reason to use an older one. It's not just me that recommends the HTML5 doctype, the W3C also recommend it, saying it's the "simplest and most reliable doctype declaration to use."
Older DOCTYPES
Note that these are older doctypes below. They are still valid, but the comments attributed to them were relevant for the time they were the most modern doctypes. That's no longer the case. The comments are largely obsolete but are presented here for historical reference.
HTML 4.01 Strict"http://www.w3.org/TR/html4/strict.dtd">
HTML 4.01 Strict contains all the standard HTML elements and attributes, but does not include deprecated elements. Framesets are not allowed with this DTD. Framesets have their own DTD which is listed further below.
HTML 4.01 Transitional
"http://www.w3.org/TR/html4/loose.dtd">
HTML 4.01 Transitional contains all the standard HTML elements and attributes, including presentational and deprecated elements. This is probably the most common DTD in use still, but only because there are so many web pages built before HTML began rolling out. Framesets are not allowed with this DTD. Framesets have their own DTD which is listed further below.
HTML 4.01 Frameset"http://www.w3.org/TR/html4/frameset.dtd">
The above DTD is the only option for use with framesets, but I’d be remiss if I didn’t warn you—frames are obsolete in HTML5. It may be a while, but sooner or later browsers will drop support for frames, some may already have. When that happens, pages designed with frames will be obsolete.
By the way, frames are not the same as iframes. Frames and framesets are obsolete, iframes are not. There are even older doctypes, and doctypes for other coding languages. This is probably all you need to know, however.
For you well-seasoned webmasters...remember quirks mode?