Top Tips and Tools for XHTML Validation

In this tutorial you will be learning about the top tips and tools for validating an XHTML document.


Step 1: Top 6 Tips for Valid XHTML

1. Specify a Doctype

When creating an XHTML document, one of the most important things to do first, is specify a Doctype. There are alot of (X)HTML Doctypes (22 to be exact) but the most common are HTML 4.01 Strict, HTML 4.01 Transitional, and XHTML 1.0 Strict. Each Doctype has their respective W3C specifications, but they are also defined in a machine-readable language specifying the legal structure, elements and attributes of a type of HTML.

Below is an example of the correct way to specify the Doctype for XHTML 1.0 Transitional:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>
<html xmlns=”” dir=”ltr”>

The reason for specifying a Doctype is because it defines which version of (X)HTML your document is actually using, and this is a critical piece of information needed by browsers or other tools processing the document.

2. Specify the Character Encoding

It is also very important to specify the Character Encoding of the XHTML document This works with the Content-Type of the document. There are many different types of Character Encodings for different types of documents.

Below is an example of a Character Encoding for an HTML site:

<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />

3. Encode HTML Character Entities

When writing content in your XHTML document, you will come across symbols that will need to be used. Instead of just typing out the symbol like normal, you need to use a specific code for that character.

You can see many of them with the code here.

4. Correcting Empty Tags

This step is simple. In regular HTML you were allowed to write empty tags like <hr> and <br> but in XHTML you need to correct these tags by simply changing them to <hr /> and <br />. Another common empty tag is <img src=”” mce_src=”” alt=””> so to change this into valid XHTML you would need to make it <img src=”” mce_src=”” alt=”” />.

5. Correct all HTML and Attribute Names

This step is also quite simple. When writing an XHTML document, you will come across times when you will have to do something like this HEIGHT=”10″ or FORM ACTION=”post”, but to change it to valid XHTML, you will need to change them to height=”10″ and form action=”post”. For valid XHTML, all HTML and attribute names need to be lower case.

6. Correct all Attribute Values

This step relates to the one above. When writing an XHTML document, you will come across times when you have to write something like this <td rowspan=”3″>. In regular HTML you were allowed to write it like <td rowspan=3> but for valid XHTML it would need to be changed to <td rowspan=”3″>. For valid XHTML, all attribute values need to be placed between quotation marks.

Step 2: Tools for Valid XHTML

1. W3C Markup Validation Service
2. HTML Validator: Mozilla Firefox Add-on

Leave a comment