Hacker News new | ask | show | jobs
by jeroenhd 1388 days ago
CSS classes are great at what they're designed for. I don't see the problem.

If you're afraid some random other CSS may come in and ruin your existing classes, you've got other problems. In Javascript I can override random functions in prototypes and leave you to deal with it, but that doesn't mean you should program as if I might.

I've become accustomed to writing SCSS rather than CSS to make generating properly scoped components easier. It saves a lot of declarative repetition when all I want is to style the first and last spans of a div tagged with a certain class while also styling the other components inside the div. I know there are many advanced features in CSS generation libraries but this is all I really care about.

I'm a strict believer in separation of concerns on the web. Not just because it produces cleaner code, but also because it makes custom user styles easier to accomplish.

That said, custom tags are an elegant solution I haven't really considered yet. I found out about them when I couldn't really rely on browsers supporting them and have ignored them ever since. I think they're probably the best of both worlds, though I expect many HTML generation libraries to choke on them.

1 comments

For large applications with many thousands of pages, or many thousands of engineers working on the same system, name collisions happen. It’s not just throwing “random css” into the mix, it’s that many disjointed parts of the same application suddenly become connected and interdependent. Especially with “parameter names” like “size”. You really have three choices to solve this: invent elaborate tooling to catch overuse; prepend your classes in the hope that lowers conflicts; or over specify selectors and deal with the specificity issues that fall out from this.

Custom elements are very well supported today! I’d encourage you to spend more time with them!