DEV Community

loading...
Cover image for What does a Doctype do?

What does a Doctype do?

nicolastobon profile image Nicolás Álvarez Tobón ・2 min read

Doctype is the abbreviation for the "Document type". The very first line in every web document should contain a <!DOCTYPE html> declaration.

why do we have to declare the Doctype?

The Doctype declaration informs the web browser about the type and version of HTML used in building the web document (e.g. HTML5, HTML4.0, XHTML1.0)

Do all versions of HTML have the same doctype?

In the previous version, the Doctype refers to (DTD) Document Type Declaration. The DTD defines the structure and legacy elements of an XML document. Due to the fact that they are based on (SGML) Standard Generalised Markup Language

  • Doctype HTML4.01

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

Doctypes for the previous versions requires the statement strict, transitional, frameset DTD.

  • DTD strict: contains all HTML elements and attributes, but does not include presentational or deprecated elements (like font). Frameset are not allowed.
  • DTD transitional: contains all HTML elements and attributes, including presentational and deprecated elements (like fonts). Frameser are not allowed.
  • DTD frameset: is equal to HTML4.01 transitional,but allows the use of frameset content.

DTDs tell the parser how to translate the code into what you see on the screen so that the look is uniform across different browsers.

Note: HTML5 is based on its own standard and not SGML, that's why the HTML5 doctype does not require a DTD.

Using the doctype declaration is a requirement placed upon us by (W3C) World Wide Web Consortium; without it, the HTML validators won't work (because they won't know what standard to check your code against) and the browser might render the document in a quirks mode.

Discussion (0)

pic
Editor guide