All in the Head: Document Type Definitions

517
A computer with several lines of code with DTD on the screen
Lines of code displayed on a computer desktop.

Introduction to Document Type Definitions

A Document Type Definition (DTD) sets forth a group of declarations conforming to a specific markup syntax. These definitions dictate the syntax for SGML or XML applications, notably the markup languages of HTML and XHTML. A DTD outlines the essential “building blocks” of an HTML or XHTML document.

Elements

Elements such as <head>, <body>, and <p> are defined, including how they may be nested to illustrate their parent/child relationships.



Attributes

Attributes offer additional information about an element, each with an associated value, for example, title="value".

Entities

Entities are variables used to define common text symbols like &, <, and > (representing &, <, and >, respectively).

PCDATA and CDATA

PCDATA refers to Parsed Character Data, which is text parsed by a parser, whereas CDATA is Character Data where the text is not parsed.

The Importance of a DTD

Why Do We Need a DTD?

Incorporating a DTD declaration into HTML or XHTML documents is crucial for several reasons. It validates the document against a particular version of (X)HTML through the World Wide Web Consortium (W3C) validator, ensuring adherence to web accessibility guidelines. A DTD facilitates proper document rendering and functionality across browsers by enforcing standards-compliant mode, avoiding the pitfalls of “quirks” mode that can lead to outdated and incorrect rendering of CSS and JavaScript.

The Role of DTD in Web Development

Omitting a DTD or incorrectly declaring it can force browsers into “quirks” mode, treating the document as if it were written with outdated markup and code. This can severely affect how CSS and JavaScript are interpreted and rendered, reminiscent of web development practices from the 1990s.

Implementing a DTD

How to Use a DTD

A DTD is declared in a webpage using the DOCTYPE declaration, which is case-sensitive and includes both a public identifier (its name) and a system identifier (a URI to the DTD). Although the DOCTYPE declaration contains the DTD's Uniform Resource Identifier (URI), browsers typically reference an internal list, using the URI merely as a reference point.


Example of a Correct DOCTYPE Declaration

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Recommended DOCTYPEs

The W3C website provides a full list of recommended DOCTYPEs, but a subset is particularly recommended for most web pages. These range from HTML 4.01 Strict for those uncomfortable with XHTML to XHTML 1.0 Transitional for beginners, and XHTML 1.0 Strict or XHTML 1.1 for more advanced or purist developers.

Standards-Compliant Web Pages

Producing a web page that complies with web standards starts with a correctly formed DOCTYPE declaration, ensuring that the public and system identifiers are correctly stated. This allows browsers to render the markup and code in standards-compliant mode and enables validators to check the markup and CSS, particularly important for accessibility. The choice of DOCTYPE impacts the allowed elements and attributes, influencing the strictness of presentational markup separation from structure.

Original article “All in the Head: Document Type Definitions” by Karl Dawson, January 2006, https://www.thatstandardsguy.co.uk/ updated by SearchGo in December 2023.


References and Citations

  1. World Wide Web Consortium (W3C) – For comprehensive standards and guidelines: https://www.w3.org/
  2. HTML5 Specification – Latest standards and guidelines for HTML5:
    https://www.w3.org/TR/2011/WD-html5-20110405/
  3. Quirks Mode and Standards Mode – Explanation of browser rendering modes:  https://developer.mozilla.org/en-US/docs/Web/HTML/Quirks_Mode_and_Standards_Mode

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here