DOCTYPES and SharePoint

I got asked by two separate friends of mine just within a few days of each other if I had any recommendations for what DOCTYPE tag should be used in SharePoint.  Honestly up until that point, I had not put a lot of thought into outside of the attitude of look up whatever A List Apart recommends and use that.   So I delved into it a bit more and now I do have an opinion on the matter.

A little info first, DOCTYPE is short for Document Type Declaration. A DOCTYPE associates a web page with a Document Type Definition (DTD).  The DTD is the definition of the particular version of HTML or XHTML you are using in your site and is what will be used for rendering of the web page.  For DTDs, there are generally 3 types, strict, transitional and frames.

Strict means there isn’t presentational elements in your code, such as formatting and alignment.  Instead everything has be to controlled separately in the CSS.   Transitional allows both CSS and presentational elements in the code.  Frames, well is for frames and if you are still using those we need to chat.   🙂

Based on your DTD and what browser you are viewing your site in, your page will render in Standards mode or Quirks mode.  Standards mode renders the page based on the DTD you defined. Quirks mode will render the page the best it can while emulating older browsers.  If you don’t define a DTD to use, the browser will default to Quirks mode.

So what about SharePoint?  First off, note that default.master does not specify a DTD! The publishing master pages (blueband, blackband, etc) use the HTML 4.0 Transitional DTD that renders in Standards mode.

For my base master pages, I put in a DOCTYPE that uses the HTML 4.0 transitional DTD that will render the site in quirks mode.   Why?  It is the lowest common denominator and appropriate for the general use of the master page.  This is not to say this is the DTD you should be using for your site.  Ultimately, you need look at the site’s target audience and purpose and select a DTD based on your individual site needs.

However, I do think Transitional DTDs should be used since there is a lot of rendered code with out of the box SharePoint that you don’t have control over, therefore your page will have presentation elements in the code and not solely use CSS for formatting.  That and Transitional is best when you use tables for page layout.   Tables vs. CSS positioning wars aside, out of the box SharePoint makes heavy use of tables for layout so stick with the transitional DTDs.

I personally don’t use the XHTML DTDs because I have yet to see justification for using them, and I get a bit worried about the fact that XHTML 1.0 won’t be supported in XHTML 2.0 and vice versa.  It seems to me if you go with a XHTML DTD, you are limiting yourself.  But again, this goes back to what does your site need, not what makes me nervous.

Another important thing about DTDs, is you need to select one BEFORE you delve too deep in developing your user interface.  The DTD you specify in the DOCTYPE tag will affect how your page is rendered, so don’t write a bunch of HTML and CSS and then apply or change the DTD, many of your page elements could go out of whack and you will have to rewrite some of your code.

Here are the two DTDs I think are best for SharePoint:

HTML 4.0 Transitional in Standards Mode (use this one if you can):
<!DOCTYPE html PUBLIC “-//W3C//DTD html 4.01 Transitional//EN” “”>

HTML 4.0 Transitional in Quirks Mode:
<!DOCTYPE html PUBLIC “-//W3C//DTD html 4.01 Transitional//EN”>

Here are some additional resources:

UPDATE 1/25/08: Well DOCTYPES must be in the air, Waldek Mastykarz just posted about DOCTYPEs as well, and recommended the use of XHTML 1.0 Strict or Transitional DTD.  He talks about his reasonings and the benefits, drawbacks and challenges with this approach.  For a different viewpoint, read his article here.

UPDATE 3/10/08: Randy Drisgill has tested SharePoint in the next version of Internet Explorer, IE8, and has a recommendation to include the meta tag that forces IE8 to render the web page based on IE7 parameters.
<meta http-equiv=”X-UA-Compatible” content=”IE=7″ />

7 thoughts on “DOCTYPES and SharePoint”

  1. I built a SharePoint site using your minimal master with the HTML 4.0 Transitional and experienced the following problems:1) I was unable to edit list data in grid view as IE 7 would invariably hang.2) The Organisation Chart web part from ContentAndCode would not render correctly.Both issues were resolved by completely removing the DOCTYPE ala default.master.RegardsAndy

  2. I agree that 4.01/Transitional should be used. I read the Waldek Mastykarz article and it is very informative but – No completely – factual. SharePoint 2007 will not ever be standards compliant; if one could reduce W3C HTML Validation errors below 75 per page, I would be very surprised. The site I recently worked showed 100+ errors per page: all out-of-the-box, auto-generated by SharePoint.As for ASP NET 2.0, browsers’ error handling solves those issue.And, thank you very kindly for the resources mention.

  3. Adding the loose doctype causes the dataview to only display 7 lines in IE6 removing it makes the full page length show. Unfortunately I built my master pages based off the minimal.master example which did use a doctype of loose but I need the full length gridview! Removing the doctype is not all that easy since it also changes both my left and upper navmenus.

  4. Forgive me if I ask a silly question, but I’m new to this.I’m having difficulty understanding how my excel and access files, are saved, exported, rendered, into xml so I can bring them into sharepoint designer (I’ve tried saving them as .xml, but it still won’t come into sharepoint designer.) Do I need to create new xml files, and bring the data in, or export it in, how?ThanksGeorgia

  5. If you are using Microsoft AJAX, then you have to use Transitional. This is great, but I built a custom menu and it does not work with the Transitional setting. 🙁 However AJAX works great.

  6. @Andy: What is the exact problem with grid view in HTML transitional? Did you find out what causes the problem?

  7. The following doctype…<!DOCTYPE html PUBLIC “-//W3C//DTD html 4.01 Transitional//EN” “”>.. adds a lot of additional work during branding, and does quirky things with classes specifically .ms-SPLink. SharePoint is best left with no DocType.

Comments are closed.