| Common Validation Errors |
|
|
|
|
We now have several threads that deal with common HTML validation problems. And the more people work toward writing valid code, the more challenges we'll see. I'd like to collect the ANSWERS we find here on this thread - similar to the generic javascript thread we already have. If you are looking for help on a specific validation error, don't post that here, start a new thread. Then, if the answer we find is common enough, we can add it here after the issue is resolved. Improper Nesting of Tags Some browsers do very creative tag handling to work around nesting erors -- they will automatically assume the next closing tag is what it should be and they will IGNORE what your code actually says. So the browser will read this: <b><i>word word</b>word</i> as if it were: <b><i>word word</i>word</b> That can give you some unexpected results. It's best to nest properly! Unclosed Tags Inline Element Cannot Contain a Block Level Element HTML has two types of elements - block level (like div, p, table) and inline (b, i, font, em, etc). Block level elements stake out a block or box on the page. They may contain other block level elements or inline elements. But in valid code, an inline element cannot contain a block level element. The most common reason for this error is wrapping one set of <font> tags around several <p> tags. For code to be valid, each <p> tag needs its own <font> and </font> before the next <p> comes along. That's one reason the font tag is deprecated - it's very, very messy and resource wasteful!
Missing alt tags: makes you regret the 42 spacer.gif's you needed to make that fancy new table work... Missing quotation marks for element attributes (xhtml validation) Deprecated tags! While these may only produce Warnings and not actually prevent validation, it is time to put deprecated tags to rest. Four of the most common:
<script language=javascript src=script.js></script> Not defining javascript type... <script language=javascript src=script.js type=text/javascript></script>
If you want to ask a question, express an opinion, or pursue discussion of a related area, please start a new thread for that. Some good topics have already been brought up, but I don't want to pull this thread off track, so those posts have been deleted here.
<p>This is a paragraph<p> I always leave off that slash on the closing tag. It will validate in html, but not xhtml for this example.
Nesting elements has always been my nemisis; it seems no matter how attentive I may be, I always find an open div (or table) tag somewhere. This occurs fars less frequenlty now, but still often enough to keep me checking. I have gotten into the habit of quoting all attributes. I can thank XHTML for that... One other habit I have acquired is when writing css declarations I always use a semi-colon; to end each statement. I find it helps if I happen to go back and add more styles. Keeps my from scratching my head trying to figure out why my CSS isn't working.
Warnings Below are the results of attempting to parse this document with an SGML parser. Fatal Error: no document type declaration; will parse without validation I could not parse this document, because it uses a public identifier that is not in my catalog. You should make the first line of your HTML document a DOCTYPE declaration, for example, for a typical HTML 4.01 document: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> <HTML> <HEAD> <BODY> </HTML>
All HTML attributes must be HTML-escaped, including URLs in an href or src attribute. This: <a href=foo.html?a=b&c=d> is wrong. Though it may work in common browsers today, it won't if you happen to pick a name after the '&' that happens to match an HTML entity name. Or if a new entity '&c;' is added to a later version of HTML. Instead use: <a href=foo.html?a=b&c=d> The '&' will be decoded before the browser uses it as part of a URL, so the script will never see it. <fixed entity> (edited by: Xoc at 2:30 pm (utc) on April 3, 2002)
marginheight=0 marginwidth=0 The only fix for this is to utilize CSS and absolute positioning. NN4.x needs the above attributes in the <body> tag to render proper margin specifications.
<hr size=1 color=#C0C0C0> The only fix for this one is also through CSS. Or, you can do it the hard core way and make a cell with a 1px transparent gif and then assign a color to the cell.
bordercolor=#ffffff The options are to utilize CSS or create multiple tables with one of those having a cellspacing of 0, cellpadding of 1 and a table color of your choice. You then assign colors to your cells (usually white) and this gives you your table with border.
One problem I see a lot are URLs where the / in the path are written as \. Some browsers deal with it, others don't. Anoher common URL problem are spaces. They should be encoded as . Again some browsers handle the problem, other doesn't. One important issue would be whether search engine robots handle incorrect URLs. You may find that URLs that works in MSIE are dropped by some robots. In other words: Use proper URI encoding.
Forgetting to encode ampersands in <a href> All HTML attributes must be HTML-escaped, including URLs in an href or src attribute. This: <a href=foo.html?a=b*c=d> is wrong. Though it may work in common browsers today, it won't if you happen to pick a name after the '*' that happens to match an HTML entity name. Or if a new entity '*c;' is added to a later version of HTML. Instead use: <a href=foo.html?a=b*amp;c=d> The '*amp;' will be decoded before the browser uses it as part of a URL, so the script will never see it.
Could it be because of the following Warnings generated from the page's CSS when run through the W3C CSS Validator? http://jigsaw.w3.org/css-validator/validator-text.html
Look closely at the anchor CSS declarations: a:link { Visit the above page with Opera to see the troublesome rendering; the link text does not even become visible until the active state is triggered. First Rule of applying color is to supply a background-color for each and every color declarartion, avoiding the above unseable situtation. I going to check this out...
<div style=color:#000;background-color:#696969;height:5px;font-size:1px;></div> By setting the font-size to 1px you solve an inheritance issue that prevents the div's height from rendering smaller than the font-size of the parent container. For example, if the body{font-size:12px;} is the only font-size declaration, then Opera and Netscape 6.x/Mozilla will not display the hr's height at less than 12px - MSIE incorrectly forgives this of course... If you use this in a div or table, you can let the containers padding set the width, or you can add margin-right and margin-left percentages...
This appears to be because Opera is buggy with multiple pseudoclasses and applying :hover effects to things that aren't in a hover state. Take a look at http://www.people.fas.harvard.edu/~dbaron/css/test/pseudos2 for some test cases.
...all links until the sun goes super nova, should be underlined.
CSE HTML Validator is an excellent choice! But, even if you have a good validator, you must make sure to change the settings properly. Unfortunately we all know that IE and NN are not 100% compatible with each other. Therefore, you will get warnings when using attributes such as bordercolor, marginwidth, or marginheight. If you're using CSE you can make it validate pure HTML standard as well as IE and NN extensions. Very useful, and very important.
ex: <br /> or <img src=xx.gif />
I don't think omitting the DTD causes SE troubles. But open tags, bad nesting, etc might hurt a spider's ability to take in the entire page.
The problem on each of those pages: ampersands and no break spaces. I know I did it correctly when I wrote it - LOL Somehow the wicked code gremlin snuck in and changed it! Seriously, sometimes symbols do degrade into the mark-up especially if you've ever recovered your pages from a server.
The limitation is documented on the Opera site http://www.opera.com/docs/specs/#css All CSS2 selectors are supported with the exception of ... combinations with pseudo-classes before other selectors Mozilla evangelism site displayed best by Mozilla is hardly surprising news though. It's a useful reminder that the slightly more obscure corners of CSS still cause compatibility problems, even in modern browsers. Featured Links:
Google Payload
Proven Money Maker At $ 9,547 A Day.
Burn The Fat Feed The Muscle
Burn The Fat - Top Selling Fat Loss Ebook Since 2003.
Save My Marriage Today!
Have You Ever Stayed Awake at Night Stressing About Whether or Not Your Marriage Will Last ... And What You Can Possibly Do to Save It?
Ultra Hot* SpywareBot: #1 AntiSpyware
Scan your computer for hidden AdWare and Spyware, Remove them permanently.
Top Movie Downloads
Join the Internet revolution and start downloading free movies and more!
Get Google Pay-Per-Click Ads Free!
Internet Marketer Gets Million in Google Pay-Per-Click Ads FREE! ... And Makes Over 4 Million as a Result! ...And Now He's Going to Give You This Same Secret for Next to Nothing! |
| < Prev | Next > |
|---|