ValidationProblems

From W3C Wiki
Jump to: navigation, search


Top Ten MarkUp Validation Problems

@@

Todo

  • point to Tidy in the first paragraph
  • each problem should have associated sample documents and links to the validator output
  • of course, each problem should show the invalid markup
  • maybe the validator output should be contained inline
  • point to the "verbose" feature
  • links to validator docs
  • link to CSS Validator FAQ
  • check what to link and what not

Missing encoding information

@@

Missing document type declaration

@@

Missing "alt" and "type" attributes

@@

Ampersands ("&") in links

@@

Improper nesting of elements

Proprietary elements and attributes

@@

  • embed
  • body @leftmargin, @topmargin, @marginheight, @marginwidth
  • frameset @border, @frameborder, @framespacing
  • table @height

...

Markup in document.write()

The <script> and <style> elements in HTML 4 are very special elements. Here is an example:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>...</title>
  <script type="text/javascript">
    alert("Björn");
  </script>
</head>
<body>
  <p>...</p>
</body>
</html>


If you load the document in a browser that supports scripting, it would show you a message box containing "Björn" rather than "Björn". This is because the browser ignores markup inside the <script> element. Here is another example:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>...</title>
  <script type="text/javascript">
    alert("Comments are <!--NOT--> ignored!");
  </script>
</head>
<body>
  <p>...</p>
</body>
</html>


You will get a message box containing "Comments are ignored!" for the same reason, markup is ignored. But the browser somehow needs to know where the <script> element is finished. It was unfortunately not possible to specify that everything up to </script> is considered part of the script, instead the first occurence of </ followed by a letter A-Za-z determines the end of the element. Here is an (illegal!) example:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>...</title>
</head>
<body>
  <script type="text/javascript">
    document.write("<p>...</p>");
  </script>
</body>
</html>


In this case, the first occurence of </ followed by a letter would be </p>! If you ignore the document.write() and ignore the

(remember, markup is ignored inside the <script> element) you get something like

  <script type="text/javascript">...</p>");
  </script>


And

does not match </script>, the validator complains
  • end tag for element "P" which is not open

It isn't, is it? Remember that comments are ignored too, but let's have a look at them again


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>...</title>
</head>
<body>
  <script type="text/javascript"><!--
    alert("--> BUH!");
  //--></script>
</body>
</html>


The browser would present you a message box containing "--> BUH!". If it had ignored comments you would not see the "BUH!", would you? But let's do another (illegal!) example


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>...</title>
</head>
<body>
  <script type="text/javascript"><!--
    document.write("<p>...</p>");
  //--></script>
</body>
</html>


So the </script> </nowiki></pre>


And </p> does not match </script>. As before.

...

Confusing HTML and XHTML syntax

...


XHTML means lower-case

@@ (<META>, onMouseOver, etc.)

"non SGML" characters

@@

See also