XHtml DocType or DTD – level 200

Especially as we move to ASP.NET 2.0, it’s important to use an XHtml DocType or DTD.  ASP.NET 2.0 server controls will render valid XHtml transitional markup, so that’s the most compelling Doctype, and that’s the one I prefer, but pick one of the following:


  • XHtml 1.0 Transitional


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

  • XHtml 1.0 Frameset (if you need to use <iframe />


    • <!DOCTYPE html
      PUBLIC “-//W3C//DTD XHTML 1.0 Frameset//EN”
      “http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd”>

  • XHtml 1.0 Strict


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

The DocType needs to be the first line in the page; however, since XHtml is valid Xml, you can optionally add an Xml declaration at the top:

<?xml version=”1.0″?>

And if you do this, the Xml declaration has to first, and then the DocType would come directly after.

7 comments

  1. I left that out because it’s very difficult to get ASP.NET to emit valid Xhtml 1.1 as well as Xhtml 1.0, so I’ve settled on Xhtml 1.0 transitional.

  2. Harris

    Jeffrey,

    I took a look at the DTDs and found that the XHTML Frameset DTD is not required if you need the IFRAME element. Frameset is specifically for FRAMESET and FRAME elements; it does include the IFRAME element as well.

    XHTML Transitional defines the IFRAME element. XHTML 1 Strict does not.

    Search the DTDs for IFRAME, FRAMESET, and FRAME elements and you should find the same.

    If I’m wrong, please correct me.

    Thanks,

    Harris

  3. Sam

    I started out assuming XHTML was somehow better than HTML. Then resources like this: http://turnipspatch.com/archives/2005/05/31/xhtml-vs-html/ helped to enlighten me a bit (hopefully).

    I’ve found that by sticking to HTML4.01 strict, cross-browser compatibility is improved, and since I never used namespacing anyways (do you? I haven’t seen anyone who does in their XHTML), I lost *nothing*.

    And that really appeals to the pragmatic programmer in me. If XHTML causes more work, has it’s own quirks to work around between different broswers, and most importantly, offers me nothing in the way of advantages (come to find out I never was using the correct content-type anyways, so my XHTML wasn’t XML), then why use it?

    That’s not to say specifying a DOC-TYPE isn’t a Very Good Thing, and your message deserves a wider audience. But before jumping on the XHTML bandwagon, I think it can help to understand why or why not a certain DOC-TYPE might be appropriate for your development.

  4. Sam

    Sorry for the double-post, but are you saying that by including the XML declaration you can add XSLT processing directives for example? That would obviously be a pretty major advantage…

    It’s all a little hard for amatuers like myself to sort out. 😉

  5. While it’s true 1.x is difficult to make XHTMl compliant in any form, 2.0 emits XHTML 1.1 compliant code (mostly anyway) by default.

  6. Sam,
    Yes, if you put an Xm declaration at the top, and your page meets Xml form specs, then it is Xml, and you can treat it as such.

Comments are closed.