Home

Doctype

A doctype, or document type declaration, is a marker placed at the top of a markup document to declare the document type and the version of the markup language being used. It helps user agents such as web browsers decide how to parse and render the content and, in older systems, which formal grammar to apply for validation. The doctype is not an element of the document’s content; it is a preface that appears before the root element.

In HTML, doctypes historically pointed to a Document Type Definition (DTD) to enable standards-compliant rendering. Modern

Placement and scope vary by language. In HTML and XHTML, the doctype sits at the very top

Doctype behavior is connected to rendering modes. A missing or incorrect doctype can cause a document to

Common examples include:

- HTML5: <!DOCTYPE html>

- 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">

HTML5
uses
a
simplified
syntax:
<!DOCTYPE
html>.
This
declaration
primarily
serves
to
trigger
standards
mode
rather
than
to
link
to
a
specific
DTD.
It
remains
a
required
preface
for
proper
rendering
in
most
browsers.
of
the
document,
before
the
html
element.
In
XML,
the
DOCTYPE
declaration
can
reference
an
external
or
internal
DTD
and
may
declare
entities
or
element
definitions,
thereby
providing
a
formal
grammar
for
the
document.
render
in
quirks
mode,
emulating
older,
nonstandard
behavior.
Doctypes
are
also
used
by
validators
to
determine
the
applicable
grammar
and
conformance
rules
for
syntax
checking.