DOCTYPE Validation in XHTML/ASP.NET web pages

by Aggiorno Team 14. January 2008 02:37

The web's unbelievable pace of growth is making the internet an untidy place to wander around. Web consumers, such as desktop browsers, mobile devices and search engines, have always been very forgiving of the inconsistencies that historically HTML has allowed by means of its semi-structured definition.

Forgiveness has brought ambiguity, which in term has resulted in more than one webmaster having issues for not being able to make a site render the same in two browsers.

To the rescue come web standards, and in particular XHTML, which combines the functionality of HTML along with the strict rules of XML.  By complying with the strict rules of XML, XHTML design is more easily handled by the variety of web browsers, search engines and mobile devices that interact with the internet.

What are some of the advantages that are gained by ensuring a page is XHTML compliant and that it validates?  Let's go over a few of them one by one.

Cross Browser Compatibility

There are multiple web browsers and each compiles web pages source code differently.  This is easily noticed when HTML is not strictly formatted and the web browser has to guess what the developer intended.  The "guessing" mode of a browser is called "quirks" rendering mode, and the browser makes its best effort to figure out the programmers intention with the source code.

By applying the strict rules of XHTML and declaring the DOCTYPE for each web page, we help the browser interpret the web page.  Thus, the difference in web page appearance between browsers is significantly minimized because the web browser no longer has to guess developer intentions.  Web page appearance and in general support for standard DOCTYPE declaration and interpretation should continue to merge between web browsers as each of the major vendors increase their support for XHTML and web standards.

Improved Maintenance Productivity

Current and future advancements in XHTML support, from each web browser, also decrease development and maintenance time.  Developers using valid XHTML spend less time testing across multiple browsers because they know that the browser will not be forced into quirks mode from invalid HTML.  That equates to less time spent developing bug fixes for a specific browser which would never occur had they used valid XHTML. 

Additionally, standard compliant code typically has a better structure as well as best programming practices and therefore it is easier to understand.

Increased Performance 

Preventing web browsers from going into quirks mode not only improves web page appearance but it also improves performance.  Quirks mode causes the web browser to implement functionality that guesses how to display the web page when it reads unformatted HTML.  Obviously guess work is going to respond slower because of the amount of possible scenarios the web browser has to analyze.  XHTML eliminates the guess work for a web browser and therefore also eliminates a series of functions set aside for quirks mode, thus resulting in a faster performing web site on the client side

Search Engine Optimization

Not only do web developers have to be concerned that web pages display properly across all web browsers but they also have to be concerned that each search engine can index the web page.  If a search engine cannot correctly read an unformatted HTML page, that web page might not get returned as part of the search results.  Once again, XHTML removes all ambiguities when reading a web page therefore your site is never dropped from a search engine’s result list because of non web standard HTML.   Your SEO efforts can be improved by making the page validate following XHTML web standards.

Mobile Devices Compatibility

The recent market surge in internet enabled mobile devices has added fuel to the argument to implement XHTML.  Mobile devices have typically less memory than a desktop PC.  In order for a mobile device’s web browser to work efficiently quirks mode has generally been removed.  Thus, if your page does not comply with a web standard, chances are that it will not render as intended on a mobile device browser.

How to setup the DOCTYPE declaration?

Now that we have reviewed some of the advantages of having a page that is XHTML compliant, how do we tell the browser which standard to use to interpret the page?  This is done using the DOCTYPE declaration.

The DOCTYPE is the first instruction in a web page.  The DOCTYPE we recommend is called XHTML transitional.  It has been designed to, as its name asserts, simplify the transition from a page that does not follow the XHTML standard to one that follows the strict standard.  In general, XHTML Transitional DOCTYPE is enough to rip all the benfits described in this post. 

The correct DOCTYPE declaration is the following:

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

As a side note, it is imperative to understand that the DOCTYPE declaration may change the way in which the page is rendered.  This should be a small price to pay for all the benefits, but it is worth noting that you need to test your page once you add a DOCTYPE declaration.

Currently rated 3.4 by 7 people

  • Currently 3.428571/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , , ,

Aggiorno | Web Standards

Comments