You are here:
- Manual
- Development
- Page structure
- DocType declaration
Page structure: The DocType Declaration
On each HTML page a DocType Declaration, or Document Type Definition (DTD), must precede the ‘html’ tag. The DocType provides the browser with information on the HTML type used to code the page. This information is important for three reasons:
- Display by browsers: The most popular browsers have two modes: 'Quirks' mode and 'Standards compliance' mode. 'Quirks' mode is activated by HTML documents with old, erroneous or absent DocTypes. This mode emulates the 'buggy' behaviour of old browsers. HTML documents with correct DocTypes activate 'Standards' mode: the browser behaves more in compliance to the W3C specifications.
- Validators: An HTML 'validator' controls the correctness of the HTML syntax on the basis of the indicated DocType.
- Editors: Many HTML editors (programmes for the HTML production) use the DocType to determine which HTML version is being used.
Each HTML or XHTML document must begin with a valid DocType Declaration.
Guideline R-pd.6.1
Recommended DocTypes
A number of DocTypes are available, but a well-considered choice from the following two is recommended.
HTML 4.01 Strict:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>
XHTML 1.0 Strict:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
If XHTML is used
If XHTML is used for the markup of websites, an XML Declaration can be used for the DocType Declaration.
<?xml version="1.0" encoding="UTF-8"?>
This XML Declaration causes problems with a few browsers, however, varying from reverting to Quirks mode (different display of CSS) to refusal to display the page (a serious accessibility problem). For this reason and because of the fact that an XML Declaration is optional, for the time being its use on government websites is not recommended.
If the XML Declaration is omitted, the document can use no character set other than UTF-8 or UTF-16. See Character encoding for further information on character sets and the use of UTF-8.
In short, if XHTML is used, do not use an XML Declaration and use UTF-8 as the character set.
