css-houdini-drafts icon indicating copy to clipboard operation
css-houdini-drafts copied to clipboard

initial value for universal ("*") syntax definition should not allow CSS-wide keywords

Open dbaron opened this issue 2 years ago • 4 comments

Right now the steps for registering a custom property appear to allow the initial value for registered properties that use the universal syntax definition ("*") to be a CSS-wide keyword (such as inherit, initial, etc.). Since these values are treated specially in custom properties I think they probably shouldn't be allowed in the initial value of a registered property.

I think it's possibly also allowed in the non-universal case as well, depending on how you interpret "computationally independent".

I think these rules should throw an error in step 4 if the value given is a CSS-wide keyword. (It's possible they should also reserve default which is disallowed from being a <custom-ident>, but is not a CSS-wide keyword.)

dbaron avatar Jul 13 '22 19:07 dbaron

Also see crbug.com/1344170.

dbaron avatar Jul 13 '22 20:07 dbaron

If we remove initial from initial-value of global syntax properties, could we introduce a syntax that allows it?

Since the fallback of a variable (var(--foobar, fallback)) doesn't have to be computationally independent like the initial-value does, it would be very useful to be able to make any registered property invalid by default (and at computed value time) because it's helpful for creating CSS APIs around value composition/deliberately triggering the fallback.

@property {
  syntax: "<length>|<guaranteed-invalid>";
  intitial-value: initial;
  inherits: true;
}

JaneOri avatar Oct 08 '22 19:10 JaneOri

WebKit implements this behavior (in https://bugs.webkit.org/show_bug.cgi?id=249305) as it seems obviously correct.

I did change the associated WPT (in https://github.com/web-platform-tests/wpt/pull/37941) to allow default as it is not a css-wide keyword. While not legal as a custom ident it shouldn't be rejected at this stage for "*" syntax (a bag of arbitrary tokens).

anttijk avatar Jan 14 '23 06:01 anttijk

[CSS-wide keywords] are treated specially in custom properties. I think they probably shouldn't be allowed in the initial value of a registered property.

Sorry, but I am missing how CSS-wide keywords are treated specially...

The CSS-wide keywords can be used in custom properties, with the same meaning as in any another property.

... but it seems obvious that they do not make sense for an initial value, as opposed to a declared value.

However I am not sure I understand why they are invalid when the syntax is not *. Is it because CSS-wide keywords and substitution values are invalid when parsing against a CSS type? (as opposed to parsing against a property value definition)

I think these rules should throw an error in step 4 if the value given is a CSS-wide keyword.

I do not see this case in the WPT, but Chrome also throws a SyntaxError when the syntax is * and the initial value is an empty string (which matches <declaration-value>?, the value definition of initial-value).

edit: I remembered https://github.com/w3c/csswg-drafts/issues/9078, which mentions the validity of an empty string (or whitespace characters).

But here too, initial-value: ; syntax: "*"; seems useless to me. But it may be usefull when the syntax is not *, as noted by @JaneOri.

edit: sorry, I mixed things up here, and I do not see any use case for using a non-universal syntax with empty string as the initial value, and I am curious what use cases require initial to be valid.


Unrelated but I also wonder why the rule is invalid instead of just the declaration, although I assume (cf. #1112) that the last valid declaration wins over the previous ones, eg.:

@property --custom {
  syntax: '<color>';
  initial-value: green;
  initial-value: initial; /* valid initial-value that invalidates @property */
  inherits: false;
}

edit: never mind, checking initial-value depends on syntax, which can be declared after, however discarding CSS-wide keywords may apply at the declaration level.

cdoublev avatar Oct 20 '23 07:10 cdoublev