HTML - which doctype should I use?

What is a doctype?

The doctype tells the browser which version of HTML you are using, so that your page works in the way that you designed it. Each version of HTML looks and behaves differently, so it is important to provide a doctype. If you don't include a doctype, the browser uses quirks mode. When you provide a doctype, the browser uses standards mode.


What is quirks mode?

The browser doesn't know which version of HTML you are using, so it makes a best-guess approach to understanding your page, fixing and ignoring any errors as it encounters them. It assumes that your page was written before HTML became a standard.

Browsers implement quirks mode differently -- they each have their own quirks -- so your page will work differently in each browser.

A page with a doctype will look the same in all browsers.


Common doctypes in use today


HTML5


  <!DOCTYPE html>
  

This is the doctype to use for all new development. It is recognized by all modern browsers, and will trigger standards mode in older browsers.


HTML 4.01


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

XHTML 1.1


  <!-- XHTML 1.1 -->
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
  <!-- XHTML 1.1 Basic -->
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
 

XHTML 1.0


  <!-- XHTML 1.0 Strict-->
  <!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 HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
  <!-- XHTML 1.0 Frameset -->
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
  

See also: W3C - Recommended Doctype Declarations to use in your Web document.

Ads by Google



Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath