Friday, June 8, 2012

HTML DOCTYPE


HTML DOCTYPE - Specifies the legal structure, elements and attributes allowed in the html page.

A DOCTYPE binds a DTD (Document Type Definition) to the page so that machine can understand what to expect in the document.

There are various formats of HTML documents like HTML 4.01 Transitional, HTML 4.01 Strict, and HTML 4.01 Frameset, etc. To tell machine which document format to consider we use HTML DOCTYPE as very first line of the HTML document. That also means no comments before the DOCTYPE declaration.

It is used in modern browsers for triggering appropriate rendering mode so the page will render properly.

DOCTYPE is supported by all major browsers like IE, CHROME, SAFARI, OPERA and FIREFOX.

Example - DOCTYPE for HTML 4 STRICT mode:
<!DOCTYPE HTML PUBLIC “-//W3c//DTD HTML 4.01 STRICT//EN” href= “http://www.w3.org/TR/html4/strict.dtd”>

You might have noticed that there is no closing of DOCTYPE, it is not required.

Now let’s see what information a HTML DOCTYPE declaration holds in a page.

<!DOCTYPE - States DOCTYPE declaration goes here.

HTML - Type of Document (HTML  default)

PUBLIC – Type of DTD publically available (Public/System)

“- - Tells whether if the organizations are registered for ISO standards (+ for yes / - for no).

// - Is separator

W3C – Organization responsible for DTD creation and maintenance (other is IETF)

//

DTD HTML 4.01 STRICT (DTD + Html version + Format) 
          
//

EN” - Language used for creation of reference object (DTD)

href= “http://www.w3.org/TR/html4/strict.dtd – Location of DTD file.

>  end of DOCTYPE declaration.

Various formats of DOCTYPE are STRICT, TRANSITIONAL and FRAMESET.

View list of various DOCTYPES at  http://www.w3.org/QA/2002/04/valid-dtd-list.html

Sample HTML file with DOCTYPE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 STRICT//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <!-- title tags and meta tags here also include styles and script-->
  </head>
  <body>
    <!-- all information for your users here -->
  </body>
</html>

Reference:


No comments:

Post a Comment