Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XHTML doctype components and reason for their existence

Tags:

html

doctype

I have started developing on the client side recently using JQuery and JavaScript. To be honest I have always taken the DOCTYPE tag for granted and I have never done much reading into it: http://www.w3schools.com/tags/tag_doctype.asp. I understand there are different doctypes for XHTML 1 (3 in total) HTML 4.01 (3 in total) and HTML 5. The doctype contains the following structure for 'HTML 4.01 Transitional':

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

I do not understand the reason for having: -//W3C//DTD HTML 4.01 Transitional//EN. Surely the DTD path is enough? I also do not understand why it is so difficult to remember e.g. why not just say: W3C HTML 4.01 Transitional. I realize there is a reason for this but I cannot find what it is.

I have spent the last few hours searching for an answer but no luck and hence the reason for the question.

like image 747
w0051977 Avatar asked Oct 20 '22 02:10

w0051977


1 Answers

The document type declaration in HTML is formally an SGML construct, defined in the SGML standard (ISO 8879). The syntax thus follows that standard, which does not let you just omit the public identifier; it allows a syntax with just a system identifier, in practice a URL, but then the syntax would be different. When HTML was defined, it was judged better to use this syntax.

It does not matter in practice, because no browser ever implemented HTML by the book (following the SGML standard), and browsers treat doctype strings just as magic strings that may select a particular mode (quirks, standard, almost standard mode; co-call “doctype sniffing”). In JavaScript, it has no significance; you can access the doctype string in JavaScript, but that’s all.

like image 90
Jukka K. Korpela Avatar answered Nov 10 '22 20:11

Jukka K. Korpela