views:

420

answers:

17

If I've tested my pages in most major browsers, why would I need to maintain a validated code? I want to use box-shadows and corner radius if they're supported in WebKit browsers and Firefox. I don't care if they don't show up on Internet Explorer. But I keep my HTTP requests down by not including images instead.

Are there are advantages to valid code? In SEO or otherwise?

A: 

The standard is only a suggestion, as you can write your own DTD and decide shadows are part of that standard and then your page would validate just fine.
The existing standards are work in process which are being affected by many parameters, not all 100% professional/technical.
The main reason to use standards is it is said will cause your page to render the most similarly between browsers (at least those browsers who support standards :-) )

Itay Moav
A: 

As long as it works in the browsers you care about then it doesn't matter. In theory your maintenance costs might be lower with validated code.

You have to determine what the success criteria for your project is. If your program does what your client needs then just because you code is "valid" doesn't make it more magical in and of itself.

David
I think SEO and Accessibility are real reasons to have valid HTML, but I agree mostly on corporate intranets, with apps like SharePoint around valid HTML is usually the last thing on anyones mind , unfortunately.
JL
+5  A: 

Invalid css/html may become horrible to maintain. Changes may have unwanted effects, which are hard to fix.

Theo Lenndorff
A: 

"Valid" code isn't so much important as "semantic" code. If there are font tags all over the place and list tags that don't close, it'll be both difficult to maintain and hard to parse with strict and proper xml parsing engines.

Stefan Kendall
Font tags are no harder to parse than anything else either in HTML or XML. List items with no closing tags are no harder to parse in HTML, and in XML they're invalid anyway. There are other reasons why using font tags is a bad idea, parseability is not one.
thomasrutter
+2  A: 

This is no different than asking if there are advantages to writing syntactically valid C code: Such a program need not do the right thing™ but doing the right thing without valid code will be harder.

Related discussion on SO: Do you validate your websites?

Sinan Ünür
Syntactically invalid C code cannot compiled and used, but invalid HTML can be, no?
NVRAM
The compiler is checking the validity of the C code. Unfortunately, browsers are more permissive than a C compiler when it comes to accepting invalid HTML (as opposed to XHTML) but the analogy holds.
Sinan Ünür
+24  A: 
  • Google prefers it so it is good for SEO.
  • It makes your web page more likely to work in browsers you haven't tested.
  • It allows you to generate or use your page as an XML document.
  • It makes you look more professional (to some developers at least)
  • Compliant browsers can render XHTML faster than HTML in quirks mode.
  • It points out a bunch of obscure bugs you've probably missed that affect things you probably haven't tested e.g. the codepage or language set of the page.
Mike McQuaid
Thanks for sharing the link Mike, really helpful!
gAMBOOKa
No problem, a pleasure.
Mike McQuaid
I'd also add that valid code is easier to debug. If your code is normally valid, then running it through a validator when you encounter a problem (or better yet, using an editor/IDE that provides "live" validity checking) is a quick, cheap way to detect several classes of typos without having to hunt them down via the browser.
Ben Blank
(Although that doesn't mean you should blindly refuse to ship non-validating code; the OP's example is an excellent one. Remember, most rules only exist to make you *think* before you break them.)
Ben Blank
Good points Ben.
Mike McQuaid
all good points
JL
+1 Forgot one point, though: It makes a site more accessible to alternative "viewers" such as screen readers for blind visitors.
galaktor
galaktor: That applies to "browsers you haven't tested"
Mike McQuaid
That SEO test is so bogus, there are dozens of other things that would have affected the ranking.
DisgruntledGoat
+1  A: 

Validating code is one can prevent many find and hopefully fix many problems in your html/css that could cause undesired results. IMHO its more of a "common things that could be wrong" fix than a replacement for testing. If you like the look you're getting in the browsers you want, I wouldn't worry too much about the validation.

(Yeah, you can put the little badge on your website if you want everybody to know you use validation to check your site) :D

CrazyJugglerDrummer
+8  A: 

Because, only by knowing the rule, will you know when to break it.

Using browser-specific extensions isn't bad, but it is something you want to do on purpose, not blindly.

Validation points out the places where you deviate from the standard. Maybe you needed to, maybe you didn't, that decision is yours.

richardtallent
A: 

I'd say valid (X)HTML is a must, since this defines how your content can be accessed. Badly formed HTML can stop your content from being "read" by not only humans but also machines (think search-engines, spiders etc). Imagine if a bank held your account details in a badly formed XML file and then sent that XML to another bank as part of a transaction - there is a danger that the bank would mis-read the amounts due to the different way it tried to interpret the sums.

Valid CSS is slightly different as it is purely stylistic and effects presentation, not content. Therefore it is not as essential to keep it valid, so long as you don't mind different user agents presenting your content in different ways.

Dan Diplo
+6  A: 

One reason for having valid HTML is for accessibility. Screen reading software for visually impaired users works much better if the HTML on the page is valid.

Charlie
+1  A: 

There are sometimes css or html attributes that are marked 'invalid' by some validators, but you shouldn't worry about this. Using box-shadows and rounded corners is no problem at all. Browsers that do not recognize them will simply ignore them, so no trouble there. I'd even encourage you to use those - if too many people would wait using those until they're widely supported, the web's momentum would become much too large.

However, there is a reason for having a valid HTML structure in your document. It isn't hard at all, and it'll save you encounters with inconsistencies in wrongfully-shaped-document-handling across browsers.

I never really understood why we are actually allowed to write structurally invalid HTML. Document readers will most likely barf out PDFs that aren't well-formed, but HTML 5 even seems to have a formal specification for error handling...

JorenB
Not all browsers will necessarily ignore them, that's not a valid assumption.
Mike McQuaid
@Mike: True, but so far every browser I know of does just exactly that.
the_drow
+2  A: 

Ask that to all the people who wrote code that worked fine when they tested it in IE 6 and then it broke when IE started supporting the standards better.

Chuck
+4  A: 

You can't test in browsers that haven't been released yet!

Browsers tend to become more standards compliant over time. If you write standards-compliant webpages, they're more likely to still work in the next version of all existing browsers.

Ken
A: 

I'll answer by an analogy. What you are saying is like saying I like building my cars with square tires, it might not be valid everywhere, but it works for me.

If you do not make a product that can be available by a maximum of people, how do you expect your product to be known and used by a maximum of people. By ignoring people that are using IE (which is still the majority of people, by the way) your shooting yourself in the foot. You need to create something that can be used by a vast majority of people while trying to follow the standards for those browsers that do follow them.

Partial
A: 

Here is another point... If you're writing a SharePoint web part, you can just about the worst possible, messy, cruffy and dodgy HTML you could possibly imagine, and your web part would feel right at home in SharePoint.

It actually amuses me seeing purists try code valid HTML strict for a MOSS plugin when the entire framework spits out garbage.

Its no wonder you can't find anything on a corporate intranet....

JL
A: 

You should always have valid (X)HTML because there are very few occasions where the benefits of not having valid code outweighs the benefits of not having validated code.

For CSS, however, there is little reason to be as strict. All your CSS should be proper and work as intended, follow best practices and optimize where possible. Other than that, use all the browser specific experimental stuff you want, it won't noticably affect other browsers.

kmiyashiro
A: 

The best reason to follow a standard is to reduce fragmentation of the standard, which leads to instability.

If everyone breaks the standard in exactly the same way and it's well thought-out, then that's not as much of a problem. Over time the standard will evolve to match what has become the common practice. Look at how modern HTML has moved on from SGML comment rules, tag minimisation, etc, and how <!DOCTYPE html> is enough to trigger standards mode. These are all against the standards but are common practice, and now the new standards (HTML5) are even evolving to support these.

If everyone breaks the standard in a different way, through general sloppiness or through wanting to invent their own 'hack', then the standard does not evolve, but it fragments. Browsers have a harder time supporting every different direction that people have gone in to hack something so that it looks right (or just through sloppy mistakes). They've done a good job so far of remaining backwards-compatible, but it's been at the cost of a huge increase in parser complexity. Sooner or later, however, less popular or more obscure hacks or errors stop being supported, because they were just stupid ideas to begin with (various CSS selector hacks come to mind) or they were just too far out of left-field (the <layer> element, and so on).

thomasrutter