Skip to content
February 25, 2011 / Rohit

Doctype

HTML as a language is very lax. It’s unlike any of the programming languages, wherein you are not punished for committing syntax errors. Even if you have unclosed tags, malformed HTML or other syntax errors, your web-browser may still render the page correctly,. The browsers handle these errors, because the number of such web-pages is still high.

When I first learned HTML, the most basic tag which I came to know of was the <html> tag. It was supposed to be the first tag which you typed to write any web-page. And I have been creating web pages which started with the <html> all along. And all those pages have never been standards compliant, because they never had a <!DOCTYPE> tag.

The first thing which you should always write in your HTML document the <!DOCTYPE> tag. It’s necessary for browsers to render your page in a standards mode. Otherwise the browser will render your page in quirks mode and the rendering can change from browser to browser.

For HTML 4.01, your doctype should look like:

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

For XHTML, it should be:

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

For HTML5 it’s (and that’s another reason to love HTML5):

<!doctype html>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: