[csswg-drafts] [css-values][css-variables][css-mixins] Generic fallback syntax for IACVT values (#9990)

LeaVerou has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values][css-variables][css-mixins] Generic fallback syntax for IACVT values ==
With variables, you can write components that can be customized externally by doing things like:

```css
--_primary-color: var(--primary-color, oklch(...));
```

There should be a similar way to specify fallbacks for functions too. That way, people could e.g. define a function for all tints of a given color (e.g. `--color-green(20)` for a light green), and other code could try that first and provide a fallback light green if not specified.

However, rather than specifying a function or mixin specific syntax, I think we should really specify a **generic fallback syntax** for anything IACVT. 
These cases are going to keep coming up, and unlike `var()`, there is no clear syntactic fit for a function call fallback. Furthermore, even with variables there are cases where providing a fallback is painful. E.g. consider something like `oklch(90% 40% var(--hue))`. To provide e.g. a medium gray as a fallback to the whole color (rather than just a fallback for `--hue`), you need to introduce an intermediate variable. Same for `calc()`.

A generic fallback syntax could also simplify `attr()`, which currently has its [own separate fallback](https://drafts.csswg.org/css-values-5/#funcdef-attr).

In terms of syntax, I see two options:

- A new function, e.g. `fallback(<declaration-value> [ ; | , ] <declaration-value>)`. Main downside is verbosity.
- "Upgrading" `var()` to accept arbitrary values in the first argument — probably not a good idea, as it would be impossible to disambiguate variable references from `<dashed-ident>` keywords.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9990 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Friday, 23 February 2024 18:49:05 UTC