20

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?

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
HyderA
  • 20,651
  • 42
  • 112
  • 180
  • 22
    A smug feeling of self satisfaction :-) – ChssPly76 Aug 26 '09 at 22:39
  • 4
    =D but so does holding your pee then letting it go! – HyderA Aug 26 '09 at 22:47
  • 19
    What’s the point of valid english? – Gumbo Aug 26 '09 at 22:52
  • 1
    What I find hilarious is that I can't find a handful of sites in the top 1000 websites on the web that pass validation. That's how much it matters. If you use an IDE, your time is better spent coding. – Damien Roche Nov 30 '12 at 12:24
  • 6
    @Zenph: You probably wouldn’t find a site in the top 1000 without any spelling errors either. However, there is a difference between "Stakc Overflow" and "Sctka Olrfvewo". – unor Jun 10 '13 at 14:14

17 Answers17

34
  • 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
  • 9,615
  • 6
  • 33
  • 38
  • Thanks for sharing the link Mike, really helpful! – HyderA Aug 26 '09 at 22:55
  • 6
    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 Aug 27 '09 at 00:25
  • 3
    (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 Aug 27 '09 at 00:27
  • 5
    +1 Forgot one point, though: It makes a site more accessible to alternative "viewers" such as screen readers for blind visitors. – galaktor Aug 27 '09 at 19:19
  • galaktor: That applies to "browsers you haven't tested" – Mike McQuaid Aug 28 '09 at 08:19
  • 4
    That SEO test is so bogus, there are dozens of other things that would have affected the ranking. – DisgruntledGoat Sep 01 '09 at 14:55
  • "It allows you to generate or use your page as an XML document." Only if it's valid XHTML. Valid HTML is perfectly ... valid, and can't be used as an XML document. – Bobby Jack Sep 04 '11 at 18:47
  • 1
    "Compliant browsers can render XHTML faster than HTML in quirks mode." This is only [vacuously true](https://en.wikipedia.org/wiki/Vacuous_truth), because compliant browsers *never* render XHTML in quirks mode; even if you have a doctype resembling XHTML, unless you actually serve it as XHTML, what browsers see is HTML that happens to look like XHTML to the human reader. And when you do serve it properly, browsers will always use standards mode on top of an XML parser. – BoltClock Jun 15 '13 at 08:13
15

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
  • 34,724
  • 14
  • 83
  • 123
9

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
  • 10,227
  • 10
  • 51
  • 92
8

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

Theo Lenndorff
  • 4,556
  • 3
  • 28
  • 43
7

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
  • 5,337
  • 3
  • 28
  • 19
4

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
  • 234,037
  • 30
  • 302
  • 389
2

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?

Community
  • 1
  • 1
Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • 2
    Syntactically invalid C code cannot compiled and used, but invalid HTML can be, no? – NVRAM Aug 26 '09 at 22:52
  • 2
    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 Aug 26 '09 at 23:11
1

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

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
1

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
  • 25,076
  • 4
  • 67
  • 89
1

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
  • 1,831
  • 2
  • 16
  • 27
0

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 -Malimovka
  • 52,579
  • 61
  • 190
  • 278
0

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
  • 34,223
  • 3
  • 62
  • 80
  • 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. Aug 27 '09 at 19:14
0

"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
  • 66,414
  • 68
  • 253
  • 406
  • 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 May 27 '10 at 07:03
0

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
  • 9,529
  • 12
  • 42
  • 57
0

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.
  • 78,954
  • 126
  • 311
  • 459
0

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
  • 2,249
  • 14
  • 15
0

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
  • 114,488
  • 30
  • 148
  • 167