Doctypes in HTML

History

During the formative years of HTML, web standards were not agreed upon yet. Browser vendors would build new features in whatever way they wanted. There was little concern for competing browsers.

The result was that web developers had to choose a browser to develop their sites for. This meant that sites would not render well in unsupported browsers. This situation could not continue.

The W3C (World Wide Web Consortium) wrote a set of web standards to handle this situation. All browser vendors and web developers should adhere to these standards. This would ensure that websites would render well across browsers.

The changes required by the standards were quite different from some existing practices. Adhering to them would break existing non standards compliant websites.

To handle this problem, vendors began programming rendering modes in to their browsers. Web developers would need to add a doctype declaration to the top of an HTML document. The doctype declaration would tell the browser which rendering mode to use for that document.

Three separate rendering modes were generally available across browsers.

  1. Full standards mode renders pages according to the W3C web standards.
  2. Quirks mode renders pages in a non standards compliant way.
  3. Almost standards mode is close to full standards mode, but features support for a small number of quirks.

In the modern age of HTML, web standards are fully implemented in all major browsers. Web sites are generally developed in a standards compliant way. Because of this the HTML5 doctype declaration only exists to tell the browser to render the document in full standards mode.

 Doctypes - short for 'document type' - help browsers to understand the version of HTML the document is written in for better inter-pretability. Doctype declarations are not HTML tags and belong at the very top of a document. This topic explains the structure and declaration of various doctypes in HTML.

Section 2.1: Adding the Doctype

The <!DOCTYPE> declaration should always be included at the top of the HTML document, before the <html> tag.

See HTML  Doctype for details on the HTML  Doctype.

<!DOCTYPE html>

Section 2.2: HTML 5 Doctype

HTML is not based on SGML (Standard Generalized Markup Language), and therefore does not require a reference to a DTD (Document Type Definition).

HTML  Doctype declaration:

<!DOCTYPE html>

Case Insensitivity.

Per the W3.org HTML  DOCTYPE Spec:

            A DOCTYPE must consist of the following components, in this order:

            1. A string that is an ASCII case-insensitive match for the string "<!DOCTYPE".

therefore the following DOCTYPEs are also valid:

    <!doctype html>

    <!dOCtyPe html>

    <!DocTYpe html>

More Information:

While no longer in general use, there are several other doctype declaration types from previous versions of HTML. There are also specific versions for XML documents. To read more about these, and to see code examples for each, take a look at the Wikipedia article.

Post a Comment

0 Comments