Chapter 86. Validating Your Source Code


The World Wide Web Consortium (W3C) is so ape over on-spec coding that they offer to validate Web pages for free. If you want to see how well your site conforms to current standards and recommendations, this service might be of interest to you. Not only does the W3C's validator point out every last coding mistake or faux pas on a Web page, it gives you a lengthy report as to why, and it offers ways to correct the problems.

TIP

If you feel bad about receiving poor marks, just send the W3C's validator to the home page of a popular site such as Amazon or eBay.


To validate a Web page, go to http://validator.w3.org/. Enter the URL of the Web page that you want to validate, or attach an offline document and send it in. Good luck! If your page validates successfully, the W3C encourages you to display their official badge proudly by adding the following code, usually at the bottom of your page:

[View full width]

<p> <a href="http://validator.w3.org/check/referer"> <img src="/books/2/30/1/html/2/http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /> </a> </p>

To improve your page's chances, try these tips:

  • Use lowercase letters for tag and attribute names.

  • Put quotes around attribute values.

  • Some attributes, like checked and selected, don't have values. Give them values equal to their attribute name, like this:

     <input type="checkbox" checked="checked" /> 

  • Observe proper nesting. That is, close nested tags in the reverse order that you open them. The first opened should be the last closed.

  • If a tag doesn't have a closing version, like the img, br, and hr tags, include a slash before the closing angle bracket, like this:

     <img src="/books/2/30/1/html/2/image.jpg" width="200" height="100" alt="An image" /> 

  • Nest lists within li elements, like this:

     <ol>   <li>List item 1</li>   <li>List item 2</li>   <li>     <ol>       <li>Nested list item 1</li>       <li>Nested list item 2</li>     </ol>   </li> </ol> 

  • Don't embed scripts or style sheets. Link to external JavaScript or CSS files instead.

  • If you must embed scripts or style sheets, remove any comments that hide the code from incompatible browsers.



Web Design Garage
Web Design Garage
ISBN: 0131481991
EAN: 2147483647
Year: 2006
Pages: 202
Authors: Marc Campbell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net