CHAPTER 2 HTML DESIGN PATTERNS
DOCTYPE
Alias Metadata Declaration^
Problem You want to declare the type of your document so you can validate it against a Document Type
Definition (DTD). You want to ensure your document is valid. You want to ensure web
browsers follow the same rules in rendering your document.
Solution The <!DOCTYPE> prolog identifies the type and version of HTML or XHTML in which the
document is coded. In technical terms, <!DOCTYPE> specifies the type of document and the
DTD that validates the document. The W3C provides a free online service at
http://validator.w3.org/ that you can use to validate your documents.
All HTML and XHTML code should be validated. This verifies the code contains no coding
errors. If there are errors, CSS selectors may fail to select elements as expected or may even
select elements unexpectedly.
There are benefits to using XHTML. Validated XHTML documents are well formed and have
unambiguous structure. You can also use XSLT (Extensible Stylesheet Language) and XQUERY
(XML Query Language) processors to extract content and rearrange documents.
In the HTML4 era, there were two additional varieties of DOCTYPEs: strict and transitional.
Strict removes all presentational elements and attributes, and transitional allows them. I do
not recommend presentation elements and attributes, but the strict DOCTYPE may be too
strict for some needs. For example, it prohibits the start attribute in
- and the value
- , which are the only available means to control the numbering of an ordered
list. The strict DOCTYPE also prohibits
attribute in