What's the point of valid CSS/HTML?

2019-01-06 17:50发布

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?

17条回答
ら.Afraid
2楼-- · 2019-01-06 18:23

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?

查看更多
仙女界的扛把子
3楼-- · 2019-01-06 18:24

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.

查看更多
smile是对你的礼貌
4楼-- · 2019-01-06 18:25

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

查看更多
趁早两清
5楼-- · 2019-01-06 18:27
  • 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.
查看更多
We Are One
6楼-- · 2019-01-06 18:28

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...

查看更多
不美不萌又怎样
7楼-- · 2019-01-06 18:30

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.

查看更多
登录 后发表回答