Question:

Do I really need a !DOCTYPE attribute?

by  |  earlier

0 LIKES UnLike

As in. Once the website goes online, will it not function properly if I don't put that little code into the top of my html?

 Tags:

   Report

2 ANSWERS


  1. The DOCTYPE tells the browser what it's viewing.  Most browsers will know by looking at the code what it's looking at.

    However, it's bad practice and programming to exclude this.

    Either way it will work, but it may come back to bite you later on.


  2. As Benji said, the DOCTYPE tells the browser what type of document to expect. Until a few years ago, the DOCTYPE wasn't really essential and most pages displayed just fine without it. This started changing about 4 years ago when browsers started moving towards what is called, "standards compliance".

    Nowdays, browsers use the DOCTYPE to determine how to render (display) the page. Pages without DOCTYPES are treated as being made up of old, proprietary HTML and are generally rendered that way.

    This is not a problem if the pages really are old, badly-formed HTML. (Although it can be a problem with browsers and screen readers that can't properly display such code!)

    As browsers become more standards compliant pages without DOCTYPE's are likely to have more and more problems with being displayed correctly.

    The safest thing to do is to add a DOCTYPE and use one of the transitional DTD's - this allows some leeway with the HTML while giving some measure of future-proofing so browsers will continue to display your pages the way you want them to display to visitors.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.