The HTML <!DOCTYPE> Tag / Document Type Declaration

By: Dusty Arlia
Published on July 19, 2012
Last Updated on Thursday, July 16, 2015 at 7:29 PM
Total Updates: 7

The document type declaration (DTD), or doctype for short, states what type of document the page is and which standard it uses. Doctypes identify which version of HTML or XHTML you used to create the webpage. The parsing program (normally an internet browser) will then know the syntax of the document and is able to render the page properly. You use a different doctype for each different version of HTML. The rules differ subtly for each doctype.

The <!DOCTYPE> declaration is not really an HTML tag, it is an instruction to the web browser about what version of HTML the page is written in. You use a different doctype for each different version of HTML. The doctype tag (<!DOCTYPE … >) is the first tag on you HTML page. This tag is not self-closing (There is no forward slash - /). The word "DOCTYPE" should always be in capital letters. What comes after the word DOCTYPE depends on the HTML standard your webpage was written in. Today's webpages should use the HTML5 doctype. This allows them to take advantage of the advanced features offered by HTML5. Here's what the HTML5 DTD looks like:

<!DOCTYPE html>

The doctype instructs the browser how to display the page. Your doctype can also have an impact on how your CSS and JavaScript affects your webpage. With a missing or incorrect doctype tag, you run the risk of having cross-browser issues. The browser will try to guess how it thinks you want the webpage to be displayed. This is sometimes called "Quirks Mode". It's best to always include a doctype in your HTML.