HTML Doctype

What is an HTML doctype?

The first line of code in the previous step was the doctype (document type declaration) and it is used to inform the validator which version of (X)HTML you are using for your document.

HTML5 Doctype

<!DOCTYPE html>

There are a number of different doctypes which you can use and all of them allow slightly different HTML code to be used but the basic principles are still the same. For this example we’ve used the HTML5 doctype but you can use any of the doctypes below (however we would always suggest a strict doctype if possible).

HTML 4.01 Strict Doctype

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>

HTML 4.01 Transitional Doctype

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>

XHTML 1.0 Strict Doctype

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

XHTML 1.0 Transitional Doctype

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

There is an XHTML 1.1 doctype and also a frameset doctype for both HTML and XHTML but you’re unlikely to use these at all, however if you’d like to read more about doctypes there’s further reading at alistapart.com.

The HTML validator

Ensuring that your HTML is valid is extremely important as one missing character can cause inconsistencies between different web browsers. If you’re using the HTML5 doctype as we recommend above then you can upload your file and automatically test your HTML code at HTML5 validator.

If you’re using any of the other doctypes then you can check if it is valid at (X)HTML validator.

Both the validators will tell you if there are any errors, where abouts in the document they occur and suggest how you can fix it so it’s a useful tool, especially if something is looking inconsistent in different web browsers.