Common doctype declarations
HTML 4.01 Strict
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
The HTML 4.01 Strict document type puts emphasis on structure over presentation. Deprecated elements, presentational attributes, frames, and link targets are not allowed in this doctype, and visitors utilizing older browsers may render the pages with little or no flair and varied support for style sheets.
HTML 4.01 Transitional
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The HTML 4.01 Transitional document type declares and includes all elements and attributes of HTML 4.01 strict with additional support for presentational attributes, deprecated elements, and linking targets.
XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> This is the xml version of the HTML 4.01 Strict document type.
XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
This is the xml version of the HTML 4.01 Transitional document type.
As you can see, the major decision points here are whether to choose between HTML and XHTML, or between strict and transitional. The decisions you make will determine which doctype you will declare inside your web documents.
Which doctype declaration should you implement?
If you start out without a doctype at all, it will throw the browser or validation tool into what is known as “Quirks” mode and the user agent will assume the page is written in an older invalid markup and code including outdated or deprecated practices. The user agent will attempt to parse and render the content in a backwards compatibility method, possibly rendering the code and CSS down to the level of IE4 or earlier and using proprietary Document Object Models (DOM’s) specific to the browser or user agent. Not exactly how you would want your web pages and documents to be rendered if you want to ensure all user experience events and interactions match with your expectations and goals.
In most web document implementations there are two main options for selecting the correct doctype, either HTML 4.01 Transitional or HTML 4.01 Strict. XHTML alone is rarely used on the web today. If you use XHTML, it should be marked up with the application/xhtml+xml MIME type. The alternative, using XHTML but delivering it as text/html, causes numerous problems that are outlined in the document entitled “Sending XHTML as text/html Considered Harmful.”
Select the HTML 4.01 Transitional doctype for an all-around, standards-compliant document that renders in most user agents and containing all the necessary elements and attributes. Consider the transitional doctype if your web pages meet the following criteria or requirements:
- You are creating new pages and are unsure what doctype to use
- You need your page to include tables as a means for layout and also include images inside of tables
- The pages emphasize presentational markup
- You need to allow external linking to open up in new browser windows
Select the HTML 4.01 Strict doctype for full standards compliance in all current browsers and user agents with new pages that contain clean, fully compliant markup and code, and combined with CSS for both presentation and positioning. Consider the strict doctype if your web pages meet the following criteria:
- CSS is used for both layout positioning and presentation styling
- You need to increase the accessibility of the page
- You need to meet standards of compliance for all modern browsers
- The page needs to render in alternate and mobile devices
- The page will not be using presentational HTML coding
What doctype do you implement in your web documents and why?