DOCTYPE

(Referring UWEM Test: 3.2_HTML_01)

Test info

Failure cause

Invalid DOCTYPE declaration found

You used a doctype-declaration not listed in the W3C recommended doctypes: http://www.w3.org/QA/2002/04/valid-dtd-list.html

Why this may be a barrier

There is not just one type of HTML, there are actually many types defined in so called "Document Type Definitions" (short: "Doctypes"). Specifying a doctype defines which version of (X)HTML your document is actually using.
This is a critical piece of information needed by browsers or other tools processing the document. Some user-agents might not be able to present the content of the document correctly, if the document type declaration is not correct.

For more information see the W3C doctype information: http://www.w3.org/QA/Tips/Doctype"

Good Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><title>Sample: Page with valid DOCTYPE</title></head>
<body>

Some content.

</body>
</html>

Solution

Use one of the doctypes listed in http://www.w3.org/QA/2002/04/valid-dtd-list.html

References

Related WCAG 1.0 Checkpoint

3.2

"Create documents that validate to published formal grammars." [Priority 2]
WCAG 1.0 Checkpoint 3.2

Referring UWEM Test

3.2_HTML_01

This test is targeted to check that the document contains a valid document type declaration.

Related DIFI/norge.no requirements

1.11

Is the HTML code of the web site correct?
norge.no requirement description 1.11

Examples

The doctype tells the web browser what type the document is and what set of rules to use when displaying the web page. The doctype is also needed to carry out checks of the formal grammar of the document contents.

If the doctype declaration of your document is missing or invalid, you have to find out, which document type the document uses, and insert an appropriate recommended doctype declaration.

You can find out, which specific HTML or XHTML has been used, by looking at the tags and header informations of the document.
If empty tags are open, HTML is used; else the document uses XHTML. If the content type is "application/xhtml+xml" the language is XHTML 1.1; else XHTML 1.0.

  • HTML 4.01

    In the following example the doctype is not specified correctly.
    According to the style of the meta and the line-brake tags, the language of the document is HTML, so we decide to use the HTML 4.01 Transitional doctype.

    Bad example:
    <!DOCTYPE html>
    <html>
    <head>
    <title>Page with invalid doctype declaration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- ... other header information ... -->
    </head>
    <body>
    This is the content of the page.<br>
    From the style of the tags it can be followed, that the used language is HTML.
    </body>
    </html>
    Good example:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <html>
    <head>
    <title>Page with valid HTML 4.01 doctype</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- ... other header information ... -->
    </head>
    <body>
    This is the content of the page.<br>
    From the style of the tags it can be followed, that the used language is HTML.
    </body>
    </html>
  • XHTML 1.0

    In the following example the doctype is not specified correctly.
    According to the style of the meta and the line-brake tags (the tags are closed), the language of the document is XHTML. Because the content type is "text/html", the language must be XHTML 1.0, so we decide to use the XHTML 1.0 Transitional doctype.

    Bad example:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html>
    <head>
    <title>Page with incomplete doctype declaration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- ... other header information ... -->
    </head>
    <body>
    This is the content of the page.<br />
    From the style of the tags it can be followed, that the used language is XHTML.
    </body>
    </html>
    Good example:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Page with valid XHTML 1.0 doctype</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- ... other header information ... -->
    </head>
    <body>
    This is the content of the page.<br />
    From the style of the tags it can be followed, that the used language is XHTML.
    </body>
    </html>
  • XHTML 1.0 Frameset

    In the following example the doctype is not specified.
    According to the style of the frame tag (the tags are closed), the language of the document is XHTML. In the code we see, that this page specifies a frameset, so we decide to use the XHTML 1.0 Frameset doctype which uses the "text/html" content-type.
    The good example has also been expanded by titles for the frames and a noframes-section for accessibility.

    Bad example:
     
    <html>
    <head>
    <title>Frameset without doctype declaration</title>
    </head>
     
    <frameset cols="20%, *">
    <frame src="navi.html" />
    <frame src="main.html" />
    </frameset>
     
    </html>
    Good example:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>XHTML frameset with valid doctype declaration</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>

    <frameset cols="20%, *">
     
    <frame title="Navigation" src="navi.html" />
    <frame title="Main Content" src="main.html" />
     
    <noframes>
    <body>
    Alternative information for accessibility purposes.
    </body>
    </noframes>
    </frameset>
    </html>
  • XHTML 1.1

    In the following example the doctype is not specified correctly.
    According to the style of the meta and the line-brake tags (the tags are closed), the language of the document is XHTML. Because the content type is "application/xhtml+xml", the language must be XHTML 1.1.

    Bad example:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML">
    <html>
    <head>
    <title>Page with incomplete doctype declaration</title>
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
    <!-- ... other header information ... -->
    </head>
    <body>
    <p>
    This is the content of the page.<br />
    From the style of the tags it can be followed, that the used language is XHTML.
    </p>
    </body>
    </html>
    Good example:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Page with valid XHTML 1.0 doctype</title>
    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
    <!-- ... other header information ... -->
    </head>
    <body>
    <p>
    This is the content of the page.<br />
    From the style of the tags it can be followed, that the used language is XHTML.
    </p>
    </body>
    </html>