ARCHIVED - Migrating to XHTML 1.0 Strict

Warning This information has been archived because it is outdated and no longer relevant.

Archived Content

Information identified as archived on the Web is for reference, research or recordkeeping purposes. It has not been altered or updated after the date of archiving. Web pages that are archived on the Web are not subject to the Government of Canada Web Standards. As per the Communications Policy of the Government of Canada, you can request alternate formats by contacting us.

Table of Contents

1.0 Benefits of migrating to XHTML 1.0 Strict

Pages that conform to XHTML 1.0 strict:

  • are more compatible with adaptive technologies than standard HTML pages;
  • are easier to render on wireless devices, Braille readers and other specialized Web environments than standard HTML pages;
  • are easier for search engines to index than standard HTML pages, resulting in better search engine results;
  • are easier for browsers to display than standard HTML pages, resulting in better browser/platform support (to support legacy browsers, follow the HTML compatibility guidelines);
  • are XML conforming, meaning they are readily viewed, edited and validated with standard XML tools; and
  • can be created dynamically by converting XML documents using XSLT.

2.0 Coding requirements

  1. Eliminate all deprecated elements and attributes. Read Alternatives to Deprecated Elements and Attributes for more details.
  2. Always surround values in tags with double quotes.

    Correct:
    <table border="0" width="100%">

    Incorrect:
    <table border=0 width=100%>

  3. All tags (elements and attributes) must be in lowercase

    Correct:
    <table border="0" width="100%">

    Incorrect:
    <TABLE BORDER="0" WIDTH="100%">

  4. All tags must be correctly nested.

    Correct:
    <p><strong>This is a paragraph.</strong></p>

    Incorrect:
    <p><strong>This is a paragraph.</p></strong>

  5. All elements with optional end tags must be closed. The non-deprecated elements with optional end tags are:

    • <body></body>
    • <colgroup></colgroup>
    • <dd></dd>
    • <dt></dt>
    • <head></head>
    • <html></html>
    • <li></li>
    • <option></option>
    • <p></p>
    • <tbody></tbody>
    • <td></td>
    • <tfoot></tfoot>
    • <th></th>
    • <thead></thead>
    • <tr></tr>

  6. All empty tags must be closed. To do this, add a space and a forward-slash (" /") immediately before the greater-than symbol (">").

    Correct:
    <br />
    <img src="image.jpg" width="12" height="45" />
    <hr />
    <input type="text" name="tag1" id="tag1" />


    Incorrect:
    <br>
    <img src="image.jpg" width="12" height="45">
    <hr>
    <input type="text" name="tag1" id="tag1">


    The non-deprecated elements with empty tags are:

    • <area />
    • <base />
    • <br />
    • <col />
    • <frame />
    • <hr />
    • <img />
    • <input />
    • <link />
    • <meta />
    • <param />

  7. All short attributes (i.e. without values) such as multiple, selected and checked must now have values.

    Correct:
    <select name="select1" id="select1" size="4" multiple="multiple" />
    <option value="1" selected="selected">Selected</option>
    <option value="2">Not selected</option>
    </select>
    <input type="radio" name="radioGroup" id="radio1" checked="checked" />


    Incorrect:
    <select name="select1" id="select1" size="4" multiple />
    <option value="1" selected>Selected</option>
    <option value="2">Not selected</option>
    </select>
    <input type="radio" name="radioGroup" id="radio1" checked />

3.0 Using HTML Tidy to help convert Web pages to XHTML 1.0 Strict

3.1 Correcting common coding errors

HTML Tidy is an open source code-sweeping tool that can be used to quickly correct common HTML coding errors. Although HTML Tidy doesn't correct all coding errors, it can significantly reduce the amount of time and effort it takes to convert Web pages to XHTML 1.0 Strict by automatically performing many corrections that would be repetitive and time consuming to perform manually.

HTML Tidy can perform the following code corrections:

  • surround values in tags with double quotes
  • convert elements and attributes to lowercase
  • correct the nesting of elements
  • close omitted and empty tags
  • specify values for short attributes
  • replace <b> and <i> with <strong> and <em>
  • replace common deprecated elements and attributes (e.g., align) with classes
  • replace inline styles with classes
  • replace poorly-supported named entities with numeric entities
  • indent code to improve legibility

3.2 HTML Tidy availability

The HTML Tidy documentation, source code and executables are available on the HTML Tidy Web site. HTML Tidy is also available in certain Web authoring software distributions.

3.3 Recommended HTML Tidy configuration options

HTML Tidy provides the ability to enable and disable the various code corrections it can perform. Much of the code correction functionality that is critical for converting Web pages to XHTML 1.0 Strict is disabled by default. The following configuration options should be used to modify the default behaviour of HTML Tidy when converting Web pages to XHTML 1.0 Strict:

  • clean: yes
  • doctype: strict
  • drop-font-tags: yes
  • drop-proprietary-attributes: yes
  • logical-emphasis: yes
  • numeric-entities: yes
  • output-xhtml: yes
  • indent: auto
  • wrap: no
  • wrap-asp: no
  • wrap-jste: no
  • wrap-php: no
  • tidy-mark: no

A complete list of HTML Tidy configuration options is available in the HTML Tidy Configuration Options Quick Reference.