Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-values] Specs that use CSS values outside of normal style rules should provide information on calc()/non-absolute length resolution in a uniform way #10853

Open
weinig opened this issue Sep 8, 2024 · 5 comments
Labels
css-fonts-4 Current Work css-values-4 Current Work

Comments

@weinig
Copy link

weinig commented Sep 8, 2024

There is an ever growing number of places that use CSS values outside of normal style rules. There are the ones within the umbrella of CSS, such as various at-rules like @font-face, @font-palette-values, etc, and in media query syntax. And there are the ones outside that umbrella, like HTML Canvas, which uses CSS values in a number places such as for declaring colors, fonts and filters, or the Geometry module's rules for parsing a matrix from a string.

Some of these define exactly what to do with calc() and/or non-absolute length values. For instance, CSS Fonts has this to say for @font-palette-values:

Math functions, such as calc(), and also var(), and env(), are valid within descriptor values in a @font-palette-values rule. They are evaluated within the context of the root element. Relative units are also evaluated within the context of the root element.

Great stuff. But finding similar rules, even in the same spec for @font-face or @font-feature-values is not something I was able to do.

I would be very helpful if there was some uniformity across specs on how this information was defined.

@frivoal frivoal added the css-values-4 Current Work label Sep 9, 2024
@weinig weinig changed the title Specs that use CSS values outside of normal style rules should provide information on calc()/non-absolute length resolution in a uniform way Sep 9, 2024
@svgeesus svgeesus added the css-fonts-4 Current Work label Sep 10, 2024
@svgeesus
Copy link
Contributor

svgeesus commented Sep 10, 2024

So, should we replicate similar text in a bunch of places, or define it somewhere central and then reference it?

@cdoublev
Copy link
Collaborator

Based on this comment, math functions are valid everywhere a <number>/<percentage>/dimension, is accepted. Spec authors should use the corresponding <*-token> variants if they should not be valid.

In practice, UAs do not accept them everywhere a <number>/<percentage>/dimension is accepted, like in the prelude of a keyframe rule.

For arbitrary substitution values like var(), this same comment says they are only valid for property values. Unless otherwise explicitly specified, I guess, like in @font-palette-values declarations.

In practice, UAs accept var() in @page and margin rules, there are discussions to accept env() in the prelude of @media, I think first-valid() could be used in any declaration, etc.


Fwiw, I think they should not be explicitly allowed if it is implicitly allowed/disallowed in a central place. This creates confusion, unless they are explicitly allowed where they should be, which might be error-prone.

@weinig
Copy link
Author

weinig commented Sep 10, 2024

So, should we replicate similar text in a bunch of places, or define it somewhere central and then reference it?

My thought was to have some default behavior for non-style rule cases, either disallowing relative length units entirely, or using some default values (though what default values you would use for the viewport for cases that might not have access to a viewport, like some of the HTML canvas color parsing functions, is unclear).

(as I forgot to cc the relevant editors originally, doing that now, @tabatkins @fantasai).

@weinig
Copy link
Author

weinig commented Sep 12, 2024

To make sure I had issues filed to track them, I filed a bunch of issues on the places I have found so far (at least within CSS):

#10876 - [css-fonts] How should relative-length values be interpreted when used in @font-face descriptors?
#10877 - [css-counter-styles] How should relative-length values be interpreted when used in @counter-style descriptors?
#10880 - [css-animations] How should relative-length values be interpreted when used in the production in the @keyframes prelude?

as well as this one on whether calc() should be allowed in the @keyframes prelude:

#10879 - [css-animation] Is calc() allowed to be used for the production in the @keyframes prelude?

I probably missed some, so let me know if there are any additional ones to track.

@cdoublev
Copy link
Collaborator

I think they always resolve based on the computed values of the root element but it might be useful to clarify it, especially for nested @media. Consequently and to complete your list, it could be clarified for @import, which accepts a <media-query-list> in its prelude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-fonts-4 Current Work css-values-4 Current Work
4 participants