A doctype or document type declaration is an instruction that associates a particular XML or SGML document with a document type definition (DTD). In HTML, the doctype is the first line that appears in the code, even before the HTML tag. It is used to tell the web browser about the version of HTML in which the page is written.