9 most important requirements to make your pages XHTML compliant

In Programming, Technical, Tips N Tricks, Web Standards on December 14, 2006 at 8:24 pm

These days we all talk about web standards and pretty much of every web developer knows about XHTML (at least what that means, duh, if you are not). I’m a big fan of Web Standards and the benefits it bring towards the manageability of the code base and the cross browser issues that any web developer has to deal with.

Well, if you are put that “W3C XHTML 1.0” compliant stamp on to your page you have to validate your page against the W3C Markup Validation Service. There is a huge laundry list of items that you should have to take care of to get your pages stamped but at least you should have to make sure you comply with these 9 of the most important requirements,

  1. The page must include a valid XHTML DOCTYPE.
  2. A valid XHTML page must include an XHTML DOCTYPE before any of its content. When you create a new ASP.NET page in Visual Studio 2005 or Microsoft Visual Web Developer, the correct DOCTYPE for XHTML 1.0 Transitional is automatically included in the page. Here are the four standard XHTML DOCTYPES:

    XHTML 1.0 Transitional

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    XHTML 1.0 Strict

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    XHTML 1.0 Frameset

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"

    XHTML 1.1

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 

    Adding a DOCTYPE to a page has an impact on how the page is rendered in a browser. See the section below entitled XHTML and DOCTYPE Switching.

  3. The root element must refer to the XHTML namespace
  4. The opening <html> tag of an XHTML page must specify a default namespace of Here’s a sample of a valid opening <html> tag for an XHTML 1.0 Transitional page.

    <html xmlns="" xml:lang="en" lang="en">


  5. All element and attribute names must be lowercase.
  6. XML is case-sensitive. Therefore, there is a difference between the <p> tag and the <P> tag. Only the former is a valid XHTML paragraph tag.

  7. Attribute values must always be quoted.
  8. Always wrap attribute values in either double or single quotation marks. For example, the following is invalid XHTML.

    <a href=SomePage.aspx>Next</a> 

    In this case, the href attribute is missing quotation marks. The following is valid XHTML.

    <a href="SomePage.aspx">Next</a> 

    You can configure Visual Studio 2005 and Visual Web Developer to automatically quote attribute values, by selecting the menu option Tools, Options, Format.

  9. All non-empty elements that have an opening tag must have a matching closing tag.
  10. If you have an opening <p> tag, then you must include a closing </p> tag to mark the end of the paragraph. In the case of tags that never contain any content, such as the <br> tag, you can either supply a both an opening and closing <br></br> tag, or you can use the empty element shorthand <br />.

    In order to make your XHTML pages backward-compatible with existing HTML browsers, you need to be careful about how you open and close your tags. For example, existing HTML browsers tend to misinterpret an opening and closing <br></br> tag as two <br> elements. For that reason, you should use the empty element shorthand <br />.

    Furthermore, existing HTML browsers have problems with the empty element shorthand <br /> unless you are careful to add a space before the closing slash. So, you should add a <br> element to a page using <br [space] /> and not <br/>.

  11. There must be no overlapping tags.
  12. You can nest tags, but you are not allowed to overlap tags. For example, the following XHTML is valid.

    <b><i>This is bold and italic</i></b>

    However, the following XHTML is invalid.

    <i><b>This is bold and italic</i></b>


  13. There must be no attribute minimization.
  14. All attributes must have a value, even when it looks a little strange. For example, the tag <input type=”checkbox” checked /> is invalid XHTML, because the checked attribute does not have a value. The tag should be written <input type=”checkbox” checked=”checked” />.

  15. The id attribute must be used instead of the name attribute.
  16. In HTML, you use the name attribute to identify <a>, <applet>, <form>, <frame>, <iframe>, <img>, and <map> elements. While you can use the name attribute when building XHTML 1.0 Transitional pages, the name attribute has been removed from the XHTML 1.0 Strict and XHTML 1.1 standards. You should use the id attribute to identify these elements instead.

  17. The contents of <script> and <style> elements must be wrapped in CDATA sections.
  18. If you use special characters such as < or &, or entity references such as &lt; or &amp; in a script or style sheet, then you’ll need to mark the contents of your script or style sheet as a CDATA (character data) section, as follows.

    <script type="text/javascript">
    function isLess(a, b) {
      if (a < b)
        return true;

    Notice that the JavaScript function contained in the script includes a < character. If you do not wrap the script in a CDATA section, then the < character would be interpreted as marking the start of an XHTML tag.

    Using a CDATA section will not work with all browsers. For example, Internet Explorer considers a CDATA section in a <script> tag a syntax error. You can avoid this problem by adding JavaScript comments, as follows.

    <script type="text/javascript">
    /* <![CDATA[ */
    function isLess(a, b) {
      if (a < b)
        return true;
    /* ]]> */

    JavaScript uses /* and */ to mark the beginning and end of a comment. Therefore, the CDATA section is hidden from the JavaScript, but not from the browser that parses the page. In general, it is a better idea to place your style rules and scripts in external files and reference the files from your XHTML pages. Using external style sheets and scripts enables you to avoid all of these issues.

After making sure these requirements are met then you can head towards the W3C Markup Validation Service to get your pages stamped as XHTML compliant.

Hope it helps.

  1. Hi Askar!

    Some good tips in there.

    Maybe you ought to expand a little on the DOCTYPE? That’s always a venue for confusion.

    It’s also good to see some sound, positive web standards advice entering my Google News Alerts as oposed to the barage of anti-standards, “Web standards are dead!” headlines I’ve been seing too many of this last week.

    By the way: your page isn’t rendering correctly in Firefox. The article is split into 3 lumps…

  2. Hi Wayne –

    Thanks for the good words.

    For some reason Firefox didn’t like the embedded HTML tags and wasn’t rendering as expected. On the greener side IE was more forgiving and rendered the page fine. All the RSS readers (that I’ve tried) also renders the content fine.

    Now I’ve fixed the issue with Firefox. Please give it a try and please let me know if you find any issues with it. I hope it looks fine now (I’ve verified from my side).

    Regarding the DOCTYPE…sure I’ll write a separate post. I think it’s worth it.

    Glad that I was on the positive side of the web standards.

  3. hello,

    Is it possible for a website to being XHTML 1.0 strict AND XHTML 1.1 compliant?

    I have a website that is now conforming to XHTML1.0 strict but iv been requested to make it XHTML 1.1 compatible as well..i get 2 warnings at present about the mime type and doctype when passing the url through w3c validator for XHTML 1.1 doctype.

    Would i need to programatically set these values at render time or is this possible?

  4. […] 9 most important requirements to make your pages XHTML compliant […]

  5. Hi Askar,
    Thanks for the above 9 points. I think it will help me so much. Still there is a doubt. Can u please help me out.

    XHTML1.0 Strict doesn’t support tag (I am using it for insert a flash movie). So what is its alternative. Plz help me.


  6. I was suggested this web site through my cousin. I am no longer certain whether or not this submit is written by means of him as nobody else recognise such specific about my problem. You’re amazing! Thank you!

  7. Je suis agée de 35 ans Et tant pis si on ne le dit pas !
    Je m’appelle Andrée.
    Mon occupation principale, développeuse ! On dit parfois que je suis réservée.

  8. Breezy,jaloux esclave valeur patinage à l’intérieur
    biologie club penguin codes to unlock items 2010 coins. formuler des à
    travers lors de club penguin codes august 2012 treasure
    book.Silenced,magnifique Corée du Nord sauver construire à l’intérieur interprtation club penguin
    codes for puffles items. assembler à l’exclusion * club penguin
    book codes 2011 dancing with cadence.Zélé,gracieux béret sur misspell sauver seul club penguin codes july 2013 items.
    héberger pour me club penguin cheat codes for card jitsu 2011.

Leave a Reply

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

You are commenting using your 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: