2

Does there exist a CSS validator where one could hint inside a file, á la jslint, what validation rules are and are not effective inside this file or a rule.

I tried

  • W3C validator

  • csslint

Neither of them offers this functionality and always lead to validation errors for a mark-up which one wants to use (IE hacks, vendor extensions)

To clarify matters further: I'd like to use this validator in a commit hook to catch CSS which does not conform the project policy. I am not that interested if people think if vendor prefixes are good or bad.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • "I'd like to use this validator in a commit hook to catch CSS which does not conform the project policy." Then you've been looking at the wrong tools, because tools like W3C specifically say that vendor prefixes are not in the standard. – BoltClock May 22 '12 at 12:09
  • This is not the case. http://jigsaw.w3.org/css-validator/ - see More Options - Vendor Extensions - Default. – Mikko Ohtamaa May 22 '12 at 12:11
  • See my reply to balpha's comment in my answer, as well as the first paragraph of the link within my answer. – BoltClock May 22 '12 at 12:14
  • @BoltClock can you then point me to the direction of right tools? I want to ignore issues regarding vendor prefixed properties due to real-life constrains. – Mikko Ohtamaa May 22 '12 at 12:17

1 Answers1

1

I don't believe there is a tool out there that's sophisticated enough to find all stylesheets that your page links to and offer customized validation rules for each stylesheet.

What I always do is isolate my IE hacks in a separate file, hidden in a conditional comment, so the validator never sees them even if I pass the URI of my page which links to all its stylesheets.

For vendor prefixes, you can tell the W3C validator to raise warnings instead of errors, although you won't be able to get it to outright ignore them because they simply do not validate.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Hi. Thank you for your answer. Though I used IE as an example, I have run other problems with W3c validator which cannot be worked around https://www.w3.org/Bugs/Public/show_bug.cgi?id=16923 Thus I am looking for an CSS validation alternative which would allow flexibility enough for serious use – Mikko Ohtamaa May 22 '12 at 11:45
  • Also csslint does checks which are not directly related to style validy, like how selectors are being used. W3C doesn't do such checks. These checks are useful, but sometimes you wish to disable them. – Mikko Ohtamaa May 22 '12 at 11:48
  • 2
    @Mikko Ohtamaa: Um, why did you file that? Vendor prefixes being invalid is *not a bug*. The point of vendor prefixes is for experimental implementations of things that haven't yet been standardized. You cannot realistically expect these things to validate. – BoltClock May 22 '12 at 12:01
  • 1
    @Mikko Ohtamaa: Also, the W3C validator does not do checks that are completely irrelevant to the *validity* of a document. That's the whole point of a *validator*. For example, just because you use ID selectors (which CSS Lint hates) does not make your CSS file invalid, because ID selectors are part of the standard. – BoltClock May 22 '12 at 12:02
  • Prefixed properties, on the other hand, *are not part of the standard*, so will never validate. This is a fact of life, and given the proliferation and abuse of vendor prefixes, validation is becoming even less relevant. – BoltClock May 22 '12 at 12:04
  • http://www.w3.org/TR/CSS21/syndata.html#vendor-keywords <-- vendor prefixes *are* part of the standard, in a way. – balpha May 22 '12 at 12:09
  • 1
    @balpha: Vendor prefixes are mentioned in the grammar so parsers can follow it and use the prefixes accordingly, but that doesn't make the prefixed properties themselves valid. If they were, then theoretically any sort of prefix could validate. And let's not get into syntactical disparities that come with prefixes (a famous example: `-moz-border-radius`). – BoltClock May 22 '12 at 12:11
  • 1
    Yeah, that's what I mean by "in a way". My point is that it's at least debatable whether they should validate. I do agree with you that they shouldn't, though -- and that the whole thing is a mess in the first place :) – balpha May 22 '12 at 12:13