Is it really necessary to validate the code?



What does writing a valid or standard code mean?


A bit of history


The web standards


How can one write a valid code?

We just said that writing a valid code means to respect the standards defined by W3C. But how can one write a valid code?

When a web page gets developed, the first thing that is indicated in the document is the Doctype (Document Type Definition) that is necessary to inform the browser the language with which the document is edited.

To write a valid code it’s necessary to check that the markers (tag) and the attributes used  fully respect the syntax defined in the Doctype declared at the beginning of the document.

Once our web document is created, how can we verify that we have written a standard code?

How to be sure that a valid code has been written?

To control the validity of one’s code, we can use several softwares – like the Markup Validation Service offered by the W3C - that automatically controls the correctness and the respect of the standards of the document  you want to test.

The validator provided by the W3C, besides indicating eventually the errors made during the creation of the web document, provides a valid help in the correction of  such errors, reporting the code line where the error is and describing also the kind of error. Obviously to understand and correct such errors it’s necessary to comprehend the code in order to modify at the occurrence the source code of the document.

A Firefox extension for the validation of the code in real time

Validating the code of your web document on the validator’s site provided by W3C involves some complications, for example it’s not possible to monitor the validation during the development of the code,  unless one uploads the web document on the W3C ‘s valuator at every new code line edited, with a great lost of time.

If you want you can resolve this problem by installing HTML Validator, an extension for the Firefox Open Souce browser which provides all the tools necessary for the validation of the web pages directly in the window of the browser. The plugin is based  on two algorithms developed by the W3C, Tidy and OpenSP.

validate the code

Using this extension every time you surf any kind of web document, the result of the validation of the document is shown directly in the window of the browser, on the bottom right, as shown in the picture above.

What does writing a valid code involve?

Obviously writing a standard code involves some advantages, among the other things, the web document will be easily usable by all users, regardless of the browser and it shouldn’t be overlooked also the “indexation” factor as the search engine spiders could have problems properly indexing web documents containing certain markup errors.

Is a validated code always synonymous of a good code?

Attention of being fooled by the word “validated”  and the positive result  returned by the W3C valuator.

The code of a web document can also be validated but this doesn’t  mean that this code is  a good code as there’re several factors that a valuator, since we’re talking about a software, may not assess correctly.

For example web documents affected by “classness” or “divness” can also be valuated if the markers used for the creation of the web document have been used correctly, the valuator will however return a valid code. But this doesn’t mean that it’s a good code.

Let’s immediately do an example to try to better understand  what we’re saying:

<div id="big-title">

<div id="navigation">
        <li>item 1</li>

<div class="red-paragraph">
    <p>This paragraph is red</p>

The code above if it was under the verification of the valuator, would be valid as all the markers (tag) defined by the W3C guidelines have been properly used. But as we said, this code cannot be considered as an optimized code because it uses several elements that can easily do without.

Here’s an example of an optimized code that produces the same result of the previous one:

<h2 id="big-title">Title</h2>

<ul id="navigation">
    <li>item 1</li>

<p class="red-paragraph">
    This paragraph is red

As you can see in this very banal example to write only three elements (title, list and a paragraph) of an hypothetic web document, the first one uses eleven code lines while the second one only seven. This is a typical error committed by  visual editors, which fill the code of a web document with many useless elements.

With this example we have demonstrated that writing a valid code is not always synonymous of a good code.

Validate the code: Is it always necessary to pass the validation?

Assuming that for a developer being able to validate the code he’s creating usually represents a personal satisfaction as well as a challenge with himself, is it always necessary to pass the validation?

The green check mark that indicates a validated code is generated by a software in accordance with the result provided by an algorithm developed to verify the correctness of the code under exam. Considering that a software has some very strict rules,  it can happen that the code of a Web document, even if perfectly developed,  for whatever kind of banality not foreseen by the validation algorithm, may not be validated

Let’s do an example: by default the API of Twitter are based on a simple div- to add to your HTML code- containing an unordered list  (<ul></ul>) where afterwards differen tweets will be inserted uploaded via a javascript function.

    <ul id="twitter_update_list"></ul>

If we try to integrate our Twitter account inside a web document using these API, when the time comes to validate the code, we’ll receive an error message as the unordered list doesn’t contain any elements (<li>…</li>). Even in case we have perfectly developed the entire code of the web document, this would not be valid.

Can such an error compromise the validity of the entire work?

Paradoxically we can find ourselves in a situation like this:

  • a Web document is validated although it has been developed with big problems of  “divness” and “classness” or paged with tables;
  • a Web document that – even if perfectly developed  – with the integration of an element of third parties (as Google Maps or the fan box of Facebook might be) is found to have an invalid code.

Which of the two documents would you consider as more valid?

Validate the code: Extreme cases

I end this article with a final consideration: I happened to see people who, despite having chosen a  Strict type doctype for the development of their web document and then spending hours of time searching for alternative methods in the attempt to validate the code that has attributes no longer permitted, like for example the target attribute.

If we need to use the target attribute, where’s the reason to choose a strict type doctype?

Now it’s your turn: I would like to hear your opinion on the many questions raised in the last part of this article.

P.S. Twitter’s API problem  has been reported only for educational purposes , in reality it can be resolved just adding an element  of the list containing an empty space: <li> &nbsp;</li>.

Master per Web Designer Freelance
Scopri One Year Together »
[pdf]Scarica articolo in PDF[/pdf]
Tags: , ,

The Author


Author's web site | Other articles written by

Related Posts

Other articles

Here are some other articles you might find interesting:


    1. ivan pianciola
      • Chris

    Trackback e pingback

    1. Is it really necessary to validate the code?
      [...] Is it really necessary to validate the code? [...]
    2. Is it really necessary to validate the code? « Codingbird
      [...] Read More by: [...]
    3. Tweet-Parade (no.17 Apr 2011) |
      [...] Is it really necessary to validate the code? – It’s the mania of those who tend to perfection and …

    Leave a Reply

    Current day month ye@r *