Skip to content

[css-values-5] Disallow mix/random/tree-counting functions in some contexts #10982

Open

Description

@cdoublev

Based on comments in #10879, any value defined in CSS Values and Units should be valid in any context other than a property value, unless otherwise specified.

mix, random, tree couting functions, need an element, but are not explicitly disallowed in other contexts.

I would say they should be invalid in media queries and any descriptor value, and valid in the prelude of keyframe and @container rules. (It seems easier to find use cases in the prelude of keyframe rules.)

Perhaps defining the concept of element-dependent (substitution) value could help clarifying this: such value would be invalid in all contexts except those "associated" to an element, or that do not need to resolve its value (feature queries). var(), attr(), toggle(), <whole-value>, would be element-dependent subsitution values.

I do not know if any of these substitution functions should/can be valid in the HTML srcset attribute (to replace <length>), but invalid in the media attribute. I guess none is currently accepted, not even math functions.

Activity

  1. fantasai commented on Oct 8, 2024

    @fantasai
    Collaborator

    Some types of mix functions are reasonable to allow anywhere, they just represent the interpolation between two values and that's fine. We could also define something reasonable for random() outside of an element context. Agree with defining some kind of concept for element-dependent functions, though, and making such invalid (if they don't have a reasonable fallback behavior).

  2. cdoublev commented on Oct 9, 2024

    @cdoublev
    CollaboratorAuthor

    Allowing them anywhere would require making some arguments (<'animation-timeline'>, per-element) invalid in these other contexts.

  3. lilles commented on Mar 14, 2025

    @lilles
    Member

    I was thinking they should be allowed in container queries, evaluating against the container element, but then the size query container may fall back to the viewport which is not an element.

  4. lilles commented on Mar 14, 2025

    @lilles
    Member

    @tabatkins @emilio @nt1m Any opinions on whether tree-counting functions like sibling-index() should be valid parse time in:

    • @page properties
    • descriptors for @font-face and other at-rules which do not apply directly to elements
    • @container queries (this is particularly interesting since the container element can be a natural choice most of the time)
    • @media queries

    And if such functions are valid, what should they evaluate to.

  5. emilio commented on Mar 14, 2025

    @emilio
    Collaborator

    I think it makes sense to disallow them to begin with...

    Only container queries really have something resembling a sensible behavior IMO, and what should the fallback behavior be is not particularly clear...

    Disallowing it gives us more leeway to decide on what the right behavior should be once there are concrete use cases for it...

  6. tabatkins commented on Mar 14, 2025

    @tabatkins
    Member

    Yeah, I'm fine with starting with them all disallowed, parse-time invalid. We can turn them on as requested.

  7. 31 remaining items

  8. added a commit that references this issue on Mar 6, 2026
  9. kbhomes commented on Sep 6, 2026

    @kbhomes
    Contributor

    I wanted to revisit this issue for random() now that Chrome is shipping their implementation and I'm starting work on Firefox's. The (tentative) WPTs that currently exist for random() (and the behavior that Chrome is shipping) indicate that it's only usable in contexts with both an element and a property name, even if the value used neither element-scoped nor property-scoped/property-index-scoped. See: random-in-container-query.tentative.html, random-in-media.tentative.html, and other changes in commits associated with this issue.

    If I think of random() as a normal math function that simplifies when all information is known for computation, then it seems to me that it should be allowed to parse and compute depending on the <random-key> components:

    • fixed <number> and <dashed-ident> in all contexts:
      • This includes container size/style queries, media queries, descriptor values, and initial-value in @property (if you consider this random key as "computationally independent", which seems right to me).
    • element-scoped in element contexts:
      • This includes container size/style queries by resolving against the container element (as was already resolved for the tree-counting functions).
      • This excludes media queries, descriptor values, and initial-value in @property.
    • property-scoped and property-index-scoped in property declarations only:
      • This excludes container size/style queries and media queries.
      • This might exclude initial-value in @property, because even though the registered property's name could reasonably be selected as the random function's property name, this would not strictly be "computationally independent" since it uses something other than "the value of the property on the element". I can imagine authors wanting to set a random starting value for a custom property, but they would be able to use a <dashed-ident> for this purpose under this proposal.
      • This probably excludes descriptor values as they're syntactically distinct from property values? I'm not sure of a compelling use case for using the descriptor name as part of the random cache key.
    • ua-* ... not sure. Could be all contexts because it is its own value (like <dashed-ident>), or could be property declarations only because it's meant for that purpose?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions