Loading...

First, the browser would like to know who it’s dealing with.

Different versions of HTML have syntax variations, much like how different people from the same country can speak different dialects. As you know from the last lesson, the first part of an HTML document should be the DOCTYPE declaration. This tells the browser which version of HTML your document is written in.

people from different background, speaking to one another

One of the most important reasons for including a DOCTYPE is to avoid something called quirks mode. This was a failsafe that was added to browsers before there were standardized rules for web languages. Quirks mode kicks in to try to fix a webpage that has missing information or faulty syntax. Each browser has its own set of rules for quirks mode. This can make it unpredictable when designing a website, so it's best to avoid it.

In older versions of HTML, like HTML4 and XHTML, the DOCTYPE had detailed declarations. They were divided into three categories.

  • Strict -- does not allow any deprecated elements and requires proper syntax
  • Transitional -- more forgiving than strict and will allow elements that should no longer be used
  • Frameset -- same as Transitional, except this also allows the use of frameset content, which can display external documents on the website
    (Note: The <frameset> tag is deprecated as of HTML5.)

Luckily, as of HTML5, developers and designers don't need to choose between these different types. HTML5 has one, slimmed down declaration that encompasses most, if not all, of a web designer's requirements.

<!DOCTYPE html>

HTML5's DOCTYPE is sometimes referred to as a "skinny doctype" because of its bare-bones code. It is much easier to memorize than previous DOCTYPEs, and it efficiently tells the browser what version of HTML is being used.