5 Common xHTML Validation Errors

Posted in Web Development on 14 January 2010 2 comments

You can validate your website using this validation service. If you are using Opera, validating a website is just one click away : Right Click -> Validate.

Recently I have updated all my free wordpress themes to be 100% xhtml valid. After validating each of them, I found that there were some common errors, which can be solved by:

1. Adding alternate text to <img> tags

This is also known for improving your site’s SEO. Whenever you use <img> tags you have to add an alternate text. If you do not have alernate text to add, at least leave it empty like this alt=""

Invalid

<img src="" />

Valid

<img src="" alt="" />

2. Closing self-closing tags

Tags like <img> , <br> , <meta> need to be self-closed.

  • <img> -> <img />
  • <br> -> <br />
  • <meta> -> <meta />

Some other self-closing tags are:

  • <area />
  • <base />
  • <basefont />
  • <hr />
  • <input />
  • <link />

3. Do not use uppercase in tags

One example, the meta verification tag given by Yahoo! Site Explorer (Yahoo webmaster tool) is always in uppercase and not self-closed, which make my page invalid.

You have to manually change the word “meta” to lowercase and self-close the meta tag.

Given by Yahoo! – invalid

<META name="y_key" content="xxxx" >

Edited to make it valid

<meta name="y_key" content="xxxx" />

4. Validating inline javascript

If you have javascript codes in your page, you have to make it valid as follow:

Invalid

I will output "Hello world!" using javascript.<br />
 
<script type="text/javascript">
document.write('Hello world!');
</script>

Valid

I will output "Hello world!" using javascript.<br />
 
<script type="text/javascript">
//<![CDATA[
document.write('Hello world!');
//]]>
</script>

By adding cdata tag, you can make your inline javascript codes to be valid. If your javascript loaded from external js file, it will not make your page invalid so you do not have to worry about that.

5. Validating video/embed codes such as youtube video

By default, the embed codes given by youtube are not xhtml valid.

To make it valid, you can refer to the guide I wrote on last month.

Posted by zen   @   14 January 2010 2 comments
Tags :


  - 2 Comments


Fuad NAHDI says:

Excellent guide. Thanks alot.

Trackbacks

  1. Tweets that mention 5 Common xHTML Validation Errors | ZENVERSE -- Topsy.com

Leave a Reply

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Please wrap all source codes with [code][/code] tags. Powered by Source Codes in Comments
Previous Post
« G-scale Wordpress Theme – Free Premium Greyscale Theme
Next Post
12 Superb and Creative Advertisements – Part 3 »