It's a general quuestion, and none of my profs could answer it:
Why do I not have to close the <!Doctype >
-Tag in HTML?
Every other tag has to be closed, like <head></head>
or <html></html>
!
So why not <!Doctype>
?
First of all, it’s not a tag at all. In HTML versions nominally based on SGML or XML, it’s a document type declaration, which has a specific syntax defined in SGML and XML. Being a declaration about the document as a whole, it’s nothing like HTML elements, and it precedes the elements. In HTML5 in HTML syntax, it’s just a required string with no defined role. (In practice, it puts browsers to “standards mode” as opposite to “quirks mode”. Browsers do not actually read the document type definition that the declaration points to. Validators may do that.)
The relevant references are the SGML standard (not available online), the XML specification, and the HTML5 CR.
The formulation of the statement “Every other tag has to be closed” in the question is misleading in other ways, too. Closing a tag (like <p>
) and closing an element (like <p>foo</p>
) are two different things. The >
closes a tag. Elements do not always need explicit end tags, since the end can be inferred by various rules; only XHTML requires explicit end tags for all elements (if we count a “self-closing” tag like <br/>
as both a start tag and an end tag, as it is). But for this doctype thing, no end needs to be indicated or inferred, except the ending >
of the declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With