CSS Custom Functions are coming(bram.us) |
CSS Custom Functions are coming(bram.us) |
This makes perfect sense if you think about it, because the browser makers ultimately decide what goes into the browser. If the W3C was "in charge" and tried to make Google (or another browser maker) do anything, Google could simply ignore them. That system wouldn't last.
It has to work this way ... and Google (along with Apple, Microsoft, etc.) have decided this syntax is best for them (and possibly their users).
The W3C is descriptive, not prescriptive. It doesn't have any regulatory power, so it can't make design decisions or value judgements of any kind. It isn't even a separate group from the browser vendors; while individuals may join, the vast majority of active members are the developers working on the browsers.
The teeth come from the other browser vendors. They make pledges to each other to implement each other's features. They collaborate through the W3C to come to a consensus on feature designs, because a feature can't get standardized if it's not implemented by more than one vendor and it won't get implemented if the vendors can't come to a consensus.
Anything the W3C says is not how browsers should work, it's how they already work.
Bramus is a frontend web developer from Belgium, working as a Chrome Developer Relations Engineer at Google.
Exactly.
However… CSS features are a W3C specification and are an early stage [1]. It’s a process that vendors draft and agree on and can terminate.
On top of that I wouldn’t characterise improving css with functions isn’t a _churnful trendchasing_. If anything this will improve accessibility because it’ll be easier to manage size, colour, and motion preferences with better abstractions than media queries everywhere.
Custom functions have been a huge web developer request for a long, long time and is one of the remaining gaps between standard CSS and Sass/LESS, after variables and nesting shipped. Mixins are next, and they'll be good too.
Not every advancement in the web platform needs to be some kind of conspiracy.
- Google: It's implemented
- People: Screw Google and their monopolistic tactics
> If web developers would just focus on making simple
That boat is long gone. The people with money don't want that, they want a platform on which to shove ads down your throat. It's successful.
Mozilla has a revenue of like $600M. They should have no problem keeping up with popular w3c standards. Hell, even opera, with only a tiny fraction of users can keep up.
The comments here indicate that the article doesn’t do much to explain what this does or why you’d want it, but basically this gives you a way to reuse blocks of styles without needing to resort to e.g. utility classes or other hacks that get around specificity issues. The syntax doesn’t help explain that.
Shame about the syntax, but I’m used to it at this point.
Edit: Looks like mixins are planned: https://github.com/w3c/csswg-drafts/issues/9350#issuecomment...
I work on a web development platform for a living and this is the sort of thing that would be good for us; if you don’t want your website to wait for JS to render content correctly and you want to keep your CSS bundle small, there aren’t many good options.
@function --light-dark(--light, --dark) {
result: var(--light);
@media (prefers-color-scheme: dark) {
result: var(--dark);
}
}Is it more like - result is a variable that can be redefined over and over during the function, and whatever value it is at the end, is what’s returned?
If you're going to add imperative programming to CSS, just do it already. Hacking in conditionals in this way feels like a bad joke.
If I had mind-boggling amounts of money, one of the things I would do is start an organization to name and shame and give anti-awards to websites that most abuse javascript and whatever-this-will-be. Or a dang mutual fund: "Like an index fund except we don't support companies with websites that require a ridiculous amount of control over the client computer."
Wait, who am I kidding: A real activist tycoon would probably just become a shareholder and make demands.
The bulk of JS executed on websites today seem to be for 2 things:
- serving ads and tracking
- running a single-page app framework
Can something like this really derail the React/Vue train?
https://drafts.csswg.org/css-mixins-1/
I do think it's strange that using a wrapper like var() wasn't required here. Like func() or such. I'd actually rather that var() hadn't existed to begin with, but it should be consistent, at least.
So taking the article seriously and not just being glib:
This feels like a misunderstanding of how to write good CSS. Good CSS is a lot like SQL, which shouldn't be a surprise since it's centered around selectors. CSS is a set-based language. Adding general purpose functions that seem to abuse rule precedence to make conditional statements feels like a dirty hack to force CSS into an imperative model.
Now, maybe there is something to be said for the idea that, here we are, 30 years into having CSS, and people are still bad at set-description operations. Maybe there should be an imperative styling language. But it's a mistake to overload CSS to do it.
I don't know how you figured their complaint is somehow compat breakage. From what I know, CSS doesn't really have breaking changes.
Usually with really bad syntax because the original design didn't expect that to happen.
Why? If the problem is JS bundle parse time, couldn't you just have a special kind of <script> tag that opts out of compilation and runs in interpreted mode only, and stick your layout JS in there? Having two entirely separate languages seems like such a waste of effort both on the platform side, and on the web developer side having to learn so many things.
That's nuts.
The web is developing in the wrong way.
Just finished work on a new CSS framework and would have loved to have stuff like this. If it lands with baseline support, I'd be able to save a lot of footprint using these.
Chrome, Chrome, Chrome, and Chrome?
Ironically, Apple's walled garden is the last thing standing between Google and total web dominance.
A CSS issue is not going to break any site unless it causes interactive elements to overlap or be hidden from view. Most sites do not implement bleeding-edge features for this reason. Those that want to set it up will do it in such a way that there's a fallback for browsers that don't support that function.