None

DOCTYPE

January 12, 2010

The doctype at the top of your HTML controls the mode that the browser uses when parsing your HTML. If you don't put a doctype it assumes that you don't really know what you're doing and so renders using Quirks mode. Some doctypes put a browser into standards mode, and others use an "almost standards" mode. Incomplete or older doctypes will still put the browser in Quirks mode.

Almost standards mode is available in Gecko based browsers like Firefox and emulates the IE6/7 standards mode.

Quirks mode harks back to the days of Netscape and IE4, where the various browsers required the HTML to be massaged to display the site how you wanted it.

The examples below should all put the browser in standards mode.

XHTML strict

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

If you use this doctype, you can't have target attribute on a link, and you can't use any presentational markup such as widths on tables. If you want to use these, use the XHTML transitional one instead.

XHTML transitional

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

This will use an "Almost Standards" mode in Gecko based browsers like Firefox.

HTML 4 strict

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

HTML 4 loose

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

HTML 5

<!DOCTYPE html>

See Also

Tags: html doctype