Live data from Hacker News

CSS Classes Considered Harmful

keithcirkel.co.uk

1–10 of 28 posts

Re: CSS Classes Considered Harmful

#2
Wish this article dedicated time to considering whether widespread use of attribute selectors will slow down the browser, but it doesn't seem to. CSS class selectors have been aggressively optimized by browser vendors for decades, vs. selectors that just filter on an arbitrary set of HTML attributes.

Modern devices are pretty fast though, so maybe it's not an issue - but I know in the past the cost of doing CSS rule evaluation has been a problem.

Re: CSS Classes Considered Harmful

#5

Wish this article dedicated time to considering whether widespread use of attribute selectors will slow down the browser, but it doesn't seem to. CSS class selectors have been aggressively optimized by browser vendors for decades, vs. selectors that just filter on an arbitrary set of HTML attributes. Modern devices are pretty fast though, so maybe it's not an issue - but I know in the past the cost of doing CSS rule…

We use this approach, and I've wondered the same thing. The only evidence I found where it's slow is in old versions of IE. Haven't tested it myself except anecdotally, but we've had no problems with them.

Re: CSS Classes Considered Harmful

#7
The problem they describe is nonexistent. They say is bad because

    some other CSS can come along
    and co-opt what big means
Doesn't matter, because you would not style ".big" but ".card.big".

Yes, if someone would redefine "card", that would be a problem. That's why this "base class" should not be as short as just "card" but rather "userInfoCard" or something like that.

Re: CSS Classes Considered Harmful

#9
The article did a good job of explaining the problem of codifying a style ontology using only clases, and proposing a solution to that problem (custom attributes and pseudo selectors for specialization). It did not convince me that classes themselves were bad, and replacing them with custom tags doesn’t seem to solve anything. The main argument advanced against classes (as opposed to certain ways of using classes) seems to be that they are old tech, which doesn’t make much sense to me. Did I miss something?
Post reply on HN