CSS WG resolved to officially work on native custom functions and mixins
css.oddbird.net
css.oddbird.net
https://github.com/w3c/csswg-drafts/issues/9350#issuecomment...
> RESOLVED: Start ED of css-mixins for CSS Custom Functions and Mixins
I feel like purists who write CSS by hand don't want this kind of stuff, because otherwise they'd have switched to one of thousands of preprocessors. And people who use preprocessors and/or elaborate styling systems that take care of this stuff already.
Maybe I am getting too old and out of touch though.
Its not always appropriate but I feel CSS benefits more often than not for this
Which browsers that matter aren't evergreen at this point?
EDIT: got an answer downthread, apparently at least some sites have to deal with old versions of the mobile Safari engine because of old iPhones/iPads that can't be updated and can't run other browser engines. Another good reason to wish that iPhones/iPads permitted other browsers.
To what extent are those platforms unable to support a better browser? For instance, Firefox works all the way back to Android 5.0.
Browsers on devices (sometimes iPads, sometimes Android) that are inside touch-screen kiosks.
Some of the ones I work with are in places so remote, it would take me three or four days to reach them if a software update goes wrong. Then another three or four days to get back to the office.
This is the most important question nowadays. there are still organizations where this is tightly controlled, they use LTS releases that don't always get the updates as fast or the same etc.
Safari on iOS, which is still tied to the OS version and not evergreen yet.
If I look at https://iosref.com/ios-usage there's only half of the users on last year update and 15% of users lagging behind on a 2+ year old browser version.
So expect your average users to have a new Safari version ~1.5 year after it's been out. So the answer to that is no, it's not fast enough to be considered evergreen.
The more universally executable code you have to run in a low-trust environment which is a WWW document, the more interesting vulnerabilities can creep in.
It's too late though: https://portswigger.net/research/ublock-i-exfiltrate-exploit...
SASS is 16 years now. Less is 15. PostCSS is 10. That it took CSS WG this long to adopt useful features from those tools reflects quite poorly on the browsers.
I wish it was also stacked like SCSS. Maybe some day.
Yes, because the fewer things you depend on outside of the standard, the better.
I like standards, but my recent foray into FE development showed me that FE is an unmitigated disaster. Standardising helps that.
After those the major use-case for JS preprocessors will for most use-cases only be bundling and minification.
Just look at the history of 6to5, babel, pony/polyfills, different build systems, different module systems, multiple different syntaxes like coffeescript, multiple different type systems. IMO we are much closer to the browser now and hopefully close to getting "normal developers" to write code that runs verbatim in a "normal browser". The outliers will always be there (Svelte, elm, etc.) but for mainstream code I hope to get back to shipping the code you wrote.
I hope that we get more features from TC39 after that. I think generators and asyncIterators are underused currently. Things like pattern matching sounds interesting to get into the JS ecosystem.
I wouldn't need Sass if mixins were implemented in CSS.
It might not eliminate it for everyone, but it will for those who care.
Maybe you still use PostCSS for some auto prefixing/ backwards compat stuff but the need for that should go away as the usage numbers for unsupported browsers go down.
So I use mixins for style reuse so that I can always look at the component CSS (and follow any explicit imports) to see what styles are applied. If you have some styles from utility classes and some from component-level styles, there's always increased cognitive load because when you're looking at the component CSS you often don't realize that the utility class is there.
I get the sense that this is one of the reasons why people like Tailwind. Then there's no confusion - everything is in utility classes, in one place. But I can't read that mess. I need line breaks and separation of concerns. That's just me.
This proposal kind of scratches my itch, but from what I can tell, these functions and mixins are still globally defined, so while they're better than utility classes, they still leave a bit to be desired for me. I'd like CSS to behave like any reasonable language and use explicit imports. But I'm sure that getting imports right and avoiding blocking is not an easy problem.
I have two major objections:
- There is no way that people who are currently writing conditional CSS-in-JS would switch to a system with a more obscure syntax, where they can't just use the same variables as their normal code, pull in imports from shared themes and libraries, and so on. This proposal includes basic local scoping rules, but they are a poor imitation of what we know works in real codebases. So the audience is people who use preprocessors, and who get around the lack of e.g. arrays or dictionaries by generating sequential variable names.
- Once you actually add functions and imperative control flow, much of the existing CSS selector machinery becomes obsolete. Why should you wrap things in `@media`, when you could just have a variable or function to query? What is the criterium for determining whether something should be declarative or imperative? Will every feature end up being available in both forms? Why or why not?
I find it particularly funny that one of the examples involves applying a 'clearfix' to an element, which is a technique from the proverbial CSS stone age. That is, they are still inserting invisible pseudo-elements to make the layout behave, which shows markup and styling are tied together anyway.
The main thing CSS-in-JS lets you do is not automate this sort of style hackery, it's to create sensible wrappers and components that actually decouple layout from content in a way that is practical, stacks cleanly, and maps directly to e.g. how a designer does it in Figma.
And instead of adding e.g. endless new color manipulation functions in CSS, you should use a proper library for this. Whatever argument there was for not allowing CSS to call into JS, it starts to look ever less convincing when this is the alternative.
Maybe all we need is a more sensible interface between JS and CSS, perhaps something patterned after declarative frameworks. i.e. They should add a Color type to DOM APIs, instead of adding control flow to CSS.
The question is how will it be implemented. Personally, I always greatly preferred Stylus' approach, and never understood why Sass was so well liked. If the CSS-WG doesn't come up with its own weird syntax, it'll probably be something like Sass, which will be fine I guess.
Besides, why would the specification for CSS take into consideration anything that's not pure CSS. Do JS maintainers take into consideration that people are transpiling javascript from typescript/dart/...?
I'd imagine some advances in the CSS specs are influenced by concepts from traspiled languages such as Sass, for example, variables and nested selectors.
That, more than anything, popularized SASS in my mind
Over the past few years CSS is getting better and better. They're really pushing back on removing reasoning for using anything but the vanilla defaults.
(However, it is unfortunate that WWW is so messy that such things are even necessary)
Just look how torturous it is today to work with clac() directives using more than 3 operands.
But it is going to end up being JS, of course.
Granted the `@function` and `var(--variable)` syntax is as clunky as ever, but it’s still distinctly not JS in any way.
But I think the vector is towards everything becoming JS anyway.
I'd love to be proven wrong.
I can't imagine this ever being supported in an ePub reader _not_ based on one of the above.
At this point, why have W3C involved when Apple, Google, and Mozilla could just hash it out amongst themselves?
You don't need to build a browser that supports JavaScript, either. You could implement any other language you wanted. Python! C?! Go? Rust?
Writing a toy browser that supports small subsets of web standards is fun, and not too difficult.
The W3C facilitates that for them sow why reinvent that wheel? The W3C is not meant to be independent of other organizations involved in making the web rather made up by them.
Maybe it's naive, but it seems like just yet another betrayal of the open web and HTML as a part of that.