Invalid HTML

Using HTML that doesn't pass validation may or may not cause you problems straight away but may eventually lead to problems of some sort.

There are a number of aspects that you need to consider when using HTML that is invalid.

The first is that there is no defined standard for how invalid HTML should be treated and so one potential problem is that the HTML will be handled differently by different browsers. One example that I have come accross of this is where a person wanted to add space between the entries in a list and instead of styling the <li> tags to add space between them they added a <br> tag between the </li>&li> where it is not allowed to be. While some browsers work out what the person meant and added space between the entries, other browsers simply ignore the tag in the invalid position.

Another way in which invalid HTML can cause problems is where it comes to applying styles to it using CSS.Browsers do not applyt the CSS to the HTML as it is written in determining how the page should look, they apply the CSS to the HTML as they interpret it. With invalid HTML you will have different browsers potentially interpreting the HTML differently and then any stypes that you are applying may end up giving different results if the interpretations are significantly different from one another.

Any JavaScript in your web page that uses DOM calls will also interact with the browser's interpretation of the HTML and so again the way the JavaScript interacts with invalid HTML may differ between browsers.

The way to avoid all of these potential problems is to validate your HTML in the first place so as to get rid of the opportunity for browsers to interpret any invalid HTML in their own way. Wth HTML that is valid you ensure that any browser that correctly follows the HTML standards (which all modern browsers do) will at least interpret the HTML the same way, eliminating that as a possible cause of differences in the way your web page looks and behaves in different browsers.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow