Doc types

Rationale

Every page should have a valid Document Type Definition (DTD) and encoding declaration. The doctype declaration refers to a published code standard (Document Type Definition or DTD) to which the page claims conformance and its provision can enable modern browsers to better render the content being provided. Access technology such as speech or braille output will also be able to interpret the pages correctly.

Pages will validate properly, and display correctly in different browsers. If the DTD and the default encoding are not declared, or are incorrectly declared, the page will fail validation and the browser may not display them correctly.


Techniques

  • Doctype code must be the very first thing declared on each page, with nothing preceding it (including blank lines). The simplest initial choice of doctype is currently "HTML 4.01 Transitional". Ensure also that the DOCTYPE appears at the top of the HTML.

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

  • Frameset doctypes should use the "HTML 4.01 Frameset" DTD should be used:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"

    "http://www.w3.org/TR/html4/frameset.dtd">

  • Validate your page with the latest versions of W3C (World Wide Web Consortium) technologies where possible. Using obsolete or deprecated technologies, for example, older versions of HTML can then be highlighted and removed.

Testing tips

Verify that there is a valid DOCTYPE on every page of your site.

  • Automated tools - Missing DOCTYPES can be picked up by testing tools. The W3C HTML validator (see Further information below) can also be used to check your code to ensure the doctype is correct and valid.
  • Accessibility toolbar - Go to Validate - W3C HTML Validator AND Validate W3C CSS Validator.
  • Browser - Go to View - Source and check that the first link of code is a DOCTYPE

Further information

Compliance with WCAG 1.0

  • 3.2 Create documents that validate to published formal grammars. Priority 2
  • 11.2 Avoid deprecated features of W3C technologies. Priority 2
  • 11.1 Use W3C technologies when they are available and appropriate for a task and use the latest versions when supported. Priority 2
For more information on techniques visit the Web Accessibility Initiative techniques page.

Last updated: 11 September 2009

Make a donation

Right now we can only reach one in three of the people who need our help most.

Please make a donation and help us support more blind and partially sighted people.