JavaScript EditorBest javascript editor debugger     Ajax website 

Main Page

Previous Page
Next Page

Validating Your Code

One good tool for finding errors on a page is to run it through a validator. An (X)HTML validator will look at the DOCTYPE to see which version of HTML or XHTML you say you're using (see pages 40 and 56), compare your code against the actual specifications of that version, and then display any inconsistencies it finds. A CSS validator works similarly.

To validate your code:

First check your (X)HTML with the W3C's

Once your (X)HTML validates, you can make sure your CSS is free of errors with

Figure 22.14. That text to the right of the image isn't supposed to be so big. What's the problem?


  • Validators have a hard time getting the big picture. While they're good at noticing missing closing tags or missing quotes, they're not always so smart about what that means in the rest of the file. For example, a missing closing tag can trigger lots of error messages throughout your document. Fix the closing tag, and all of those subsequent "errors" go away. The trick, then, is to fix a few errors at a time, starting at the top of the file, and then immediately revalidate the file to see if other problems are also resolved (Figure 22.15).

    Figure 22.15. The error found on Line 9 seems to be the probleminstead of a closing </h1> tag, I've put in another opening <h1> tag by mistake. Notice how the description doesn't really have to do with our mistake. The validator often misinterprets typos.

  • Many text editors, like BBEdit, have incorporated syntax checkers. They are great for catching errors before you get to the official validator.

  • Use the DOCTYPE to tell the validator which specifications to judge your HTML and XHTML with (see page 56).

  • There are other validators out there. I think the ones from the W3C are the best.

Previous Page
Next Page

JavaScript EditorBest javascript editor debugger     Ajax website