The document type is used to trigger standards-compliance mode in browsers. While not required, its best to include it to avoid many common rendering errors.
Including the doctype is mainly done to make the browser render the page in standards-compliance mode, rather then backwards compatibility-mode.
The new HTML Doctype
HTML is currently maintained as a living standard, so further updates will not be numbered or change the doctype.
XHTML uses the same doctype, and its optional whether you want to include it. Thats because delivering pages with the application/xml mine-type, automatically triggers standards-compliance mode.
Note. Below is only included for legacy purposes. For new sites, its recommended that you use the new <!DOCTYPE html> doctype declaration.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">