Saturday, July 17, 2010

Document Type Declaration

A Document Type Declaration, or DOCTYPE, is an instruction that associates a particular SGML (HTML) or XML (XHTML) document with a Document Type Definition (DTD). (Source Wikipedia)

Example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "">

The general syntax of Document Type Declaration of (X)HTML documents is: <!DOCTYPE root-element [SYSTEM OR PUBLIC FPI] "uri">

In web pages the root element is always html. The keywords SYSTEM or PUBLIC indicate whether the DTD is stored in a private computer or a public one. If public, then the keyword is followed by a Formal Public Identifier (FPI). An FPI is a specially formatted string of text that uniquely identifies the DTD. If the SYSTEM keyword is chosen, an FPI is not necessary. The FPI in the above example is "//W3C//DTD HTML 4.01//EN". And the last item found in (X)HTML Document Type Declarations is the URI of the DTD. In the above example, it is ""

A Document Type Definition (DTD) is a set of markup declarations that define a document type for SGML-family markup languages (SGML, XML, HTML). Source: Wikipedia)

A DTD defines what elements are in the document, the attributes the elements can have, the contents of the elements etc.

These are the current Document Type Declarations used in (X)HTML pages:

HTML 4.01 Declarations
HTML 4.01 Strict
HTML 4.01 Transitional
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
HTML 4.01 Frameset
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "">
XHTML 1.0 Declarations
XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
XHTML 1.0 Frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "">

The root element (HTML) in the declaration can be lower case or upper case for HTML 4.01.

No comments: