XHTML DOCTYPES & Rules

is a declaration and the very first thing to appear in an XHTML Document, even before the tag. Its purpose along with the DTD is to give instruction to the browser about which “flavor” or version of the markup that the current page is written in.

Why is this important? Only because it defines the rules for the language being used, which then allows the browser to render your content properly. Ok, on to the differences…

XHTML 1.0 Transitional

This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.

XHTML 1.0 Strict

This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.

XHTML 1.0 Frameset

This DTD is equal to XHTML 1.0 Transitional, but allows the use of frameset content.

XHTML 1.1

This DTD is equal to XHTML 1.0 Strict, but allows you to add modules (for example to provide ruby support for East-Asian languages).

XHTML Usage Rules

  1. Add an XHTML DOCTYPE to the first line of every page:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    Tip: Your pages must have a DOCTYPE declaration if you want them to validate as XHTML.
  2. Add an xmlns attribute to the html element of every page:
    <html xmlns="http://www.w3.org/1999/xhtml">
    Note: The xmlns attribute specifies the xml namespace for a document, and is required in XHTML documents.
  3. Change Tags And Attribute Names to Lowercase – A general “find-and-replace” function was executed to replace all uppercase tags with lowercase tags. The same was done for attribute names.
  4. Quote All Attribute Values – Check every page to see that attribute values are quoted.
  5. Close all Empty Tags – Empty tags are not allowed in XHTML. See the following example:
    <hr>, <br> &amp; <img> <!-- tags should be replaced with -->
    <hr />,<br />&amp; <img with  />
    Generally if you are switching from one Doctype to another you can use a simple find and replace commend to quickly address this issue.
  6. Validate XHTML With The W3C Validator – Before an XHTML file can be validated, a correct DTD must be added as the first line of the file.
  7. XHTML Starter Snippets

    If you wanted to add a collection of XHTML starter snippets to your own Snippets Library, which EVERY web developer should have, you can jump over to my XHTML Starters Snippets post and grab some there.

    Source – w3cSchools

Join The Conversation

All comments are moderated.

* Denotes required field.

*