What is doctype

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html>
<head>
<title>Title of the document</title>
</head>


<body>
The content of the document……

</body>


</html>

You may have noticed this strange line at the start of the web pages. Whenever you create a web page in any web editor, along with the basic required HTML/XHTML elements, the editor puts such a line too. And what’s more strange is that if your remove this line, your web page still behaves the same. So what is this then actually meant for? Lets take a look.

As defined at www.w3schools.com
  • The doctype declaration should be the very first thing in an HTML document, before the <html> tag.
  • The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.
  • The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
Well let’s dissect it.

As the w3schools definition says, this is something that should be the first thing in an HTML document. Well yes but if you use it. If you don’t it doesn’t have much effect on how your web page is displayed. Which brings us to the second and third point that a Web Browser somehow needs this doctype. Well The browsers of today are so intelligent that to some extent even if your html is not correct the browser would still display the page correctly :) .

So then what is it then actually.

Doctype is a set of rules about how your write your html, what html elements are allowed to used, which ones are declared deprecated (obsolete), whether to write the elements in small caps or capital, if an attribute’s value should be enclosed within quotes etc etc.
Do when you place a doctype at the start of your HTML document, you are actually claiming that you have used certain set of rules to write your html. Still this does not force you to write your html according to the specified doctype.

So if you have specifed a doctype and your html is not according to that doctype, in case of most browsers, your web page would still be displaying correctly, its just that you html document is not a valid document. I consider this more of an ethical thing. Its as if I say to my students that every student should use blue pens to write notes but I am nit enforcing it. So if someone uses a red pen, his/her notes would do the required task (that is help him/her for reference), its just that those notes won’t be considered valid as they were not written using the specified rules.

Doctype is more of a standards issue. During my MS I studied Software Quality Management and I did an assignment on ISO and during searching for some reference material on Google, I read a very simple interpretation of ISO’s basic quality enforcements. It read:
  • Write down the steps of the procedure that you would take to do your task.
  • Do your task according to those steps.
  • You must be able to provide evidence that the task you completed was done following the exact steps that were defined in step1.
Now if you don’t follow these three rules, your task would still get completed, but it wont be according to the standard and hence not a quality product.
So in the end obviously it is better to use a doctype in your html document and then write all yoru html in that document according to the speicified doctype. If you are using any speicliazed web editor to write your html document, it would provide a built-in facility to validate your document. You can also use the W3C Markup Validation Service

Reference:

Following resources were used in writing this article.
http://www.w3schools.com/tags/tag_DOCTYPE.asp

No comments:

Post a Comment